/// <summary> /// TBD /// </summary> /// <param name="settings">TBD</param> public DedicatedThreadPool(DedicatedThreadPoolSettings settings) { _workQueue = new ThreadPoolWorkQueue(); Settings = settings; _workers = Enumerable.Range(1, settings.NumThreads).Select(workerId => new PoolWorker(this, workerId)).ToArray(); // Note: // The DedicatedThreadPoolSupervisor was removed because aborting thread could lead to unexpected behavior // If a new implementation is done, it should spawn a new thread when a worker is not making progress and // try to keep {settings.NumThreads} active threads. }
public DedicatedThreadPool(DedicatedThreadPoolSettings settings) { Settings = settings; Workers = Enumerable.Repeat(0, settings.NumThreads).Select(_ => new WorkerQueue()).ToArray(); foreach (var worker in Workers) { new PoolWorker(worker, this, false); } _supervisor = new DedicatedThreadPoolSupervisor(this); }
public ForkJoinDispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites) { var dtp = config.GetConfig("dedicated-thread-pool"); if (dtp == null || dtp.IsEmpty) throw new ConfigurationException(string.Format("must define section dedicated-thread-pool for ForkJoinDispatcher {0}", config.GetString("id", "unknown"))); var settings = new DedicatedThreadPoolSettings(dtp.GetInt("thread-count"), DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype", ThreadType.Background.ToString())), config.GetString("id"), DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp)); _instance = new ForkJoinDispatcher(this, settings); }
public DedicatedThreadPool(DedicatedThreadPoolSettings settings) { Settings = settings; Workers = Enumerable.Repeat(0, settings.NumThreads).Select(_ => new WorkerQueue()).ToArray(); for (var i = 0; i < Workers.Length; i++) { new PoolWorker(Workers[i], this, false, i); } _supervisor = new DedicatedThreadPoolSupervisor(this); }
public PinnedDispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites) { var dtp = config.GetConfig("dedicated-thread-pool"); if (dtp == null || dtp.IsEmpty) { _settings = DedicatedThreadPoolConfigHelpers.DefaultSingleThreadPoolSettings; } else { _settings = new DedicatedThreadPoolSettings(1, DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype", ThreadType.Background.ToString())), config.GetString("id"), DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp)); } }
static void CreateAndWaitForWorkItems(int numWorkItems, DedicatedThreadPoolSettings settings) { using (ManualResetEvent mre = new ManualResetEvent(false)) using(var tp = new Concurrency.DedicatedThreadPool(settings)) { int itemsRemaining = numWorkItems; for (int i = 0; i < numWorkItems; i++) { tp.QueueUserWorkItem(delegate { if (Interlocked.Decrement( ref itemsRemaining) == 0) mre.Set(); }); } mre.WaitOne(); } }
static void Main(string[] args) { var generations = 4; var tpSettings = new DedicatedThreadPoolSettings(Environment.ProcessorCount); for (int i = 0; i < generations; i++) { var workItems = 10000 * (int)Math.Pow(10, i); Console.WriteLine( "Comparing Helios.Concurrency.DedicatedThreadPool vs System.Threading.ThreadPool for {0} items", workItems); Console.WriteLine("DedicatedThreadFiber.NumThreads: {0}", tpSettings.NumThreads); Console.WriteLine("System.Threading.ThreadPool"); Console.WriteLine( TimeSpan.FromMilliseconds( Enumerable.Range(0, 6).Select(_ => { var sw = Stopwatch.StartNew(); CreateAndWaitForWorkItems(workItems); return sw.ElapsedMilliseconds; }).Skip(1).Average() ) ); Console.WriteLine("Helios.Concurrency.DedicatedThreadPool"); Console.WriteLine( TimeSpan.FromMilliseconds( Enumerable.Range(0, 6).Select(_ => { var sw = Stopwatch.StartNew(); CreateAndWaitForWorkItems(workItems, tpSettings); return sw.ElapsedMilliseconds; }).Skip(1).Average() ) ); } }
public ForkJoinExecutor(string id, DedicatedThreadPoolSettings poolSettings) : base(id) { _dedicatedThreadPool = new DedicatedThreadPool(poolSettings); }
internal ForkJoinDispatcher(MessageDispatcherConfigurator configurator, DedicatedThreadPoolSettings settings) : base(configurator) { _dedicatedThreadPool = new DedicatedThreadPool(settings); }
private static DedicatedThreadPoolSettings ConfigureSettings(Config config) { var dtp = config.GetConfig("dedicated-thread-pool"); var fje = config.GetConfig("fork-join-executor"); if ((dtp == null || dtp.IsEmpty) && (fje == null || fje.IsEmpty)) throw new ConfigurationException( $"must define section 'dedicated-thread-pool' OR 'fork-join-executor' for fork-join-executor {config.GetString("id", "unknown")}"); if (dtp != null && !dtp.IsEmpty) { var settings = new DedicatedThreadPoolSettings(dtp.GetInt("thread-count"), DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype", ThreadType.Background.ToString())), config.GetString("id"), DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp)); return settings; } else { var settings = new DedicatedThreadPoolSettings(ThreadPoolConfig.ScaledPoolSize(fje.GetInt("parallelism-min"), 1.0, fje.GetInt("parallelism-max")), name:config.GetString("id")); return settings; } }
/// <summary> /// Initializes a new instance of the <see cref="ForkJoinExecutorServiceFactory"/> class. /// </summary> /// <exception cref="ConfigurationException"> /// This exception is thrown if either 'dedicated-thread-pool' OR 'fork-join-executor' is not defined in <paramref name="config"/>. /// </exception> public ForkJoinExecutorServiceFactory(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites) { _threadPoolConfiguration = ConfigureSettings(config); }
public DedicatedThreadPool(DedicatedThreadPoolSettings settings) { Settings = settings; WorkQueue = new ThreadPoolWorkQueue(); }
public DedicatedThreadPool(DedicatedThreadPoolSettings settings) { _workQueue = new ThreadPoolWorkQueue(); Settings = settings; _workers = Enumerable.Range(1, settings.NumThreads).Select(workerId => new PoolWorker(this, workerId)).ToArray(); // Note: // The DedicatedThreadPoolSupervisor was removed because aborting thread could lead to unexpected behavior // If a new implementation is done, it should spawn a new thread when a worker is not making progress and // try to keep {settings.NumThreads} active threads. }