/// <summary> /// <see cref="DynamicThreadPool"/> constructor /// </summary> /// <param name="minThreadCount">Minimum number of threads that should always be in pool</param> /// <param name="maxThreadCount">Maximum number of threads in pool</param> /// <param name="queueBoundedCapacity">The bounded size of the work items queue (if less or equal to 0 then no limitation)</param> /// <param name="name">The name for this instance of ThreadPool and for its threads</param> /// <param name="isBackground">Whether or not threads are a background threads</param> /// <param name="options">Additional thread pool creation parameters</param> private DynamicThreadPool(DynamicThreadPoolOptions options, int minThreadCount, int maxThreadCount, int queueBoundedCapacity, string name, bool isBackground) : base(queueBoundedCapacity, options.QueueStealAwakePeriod, isBackground, name, options.UseOwnTaskScheduler, options.UseOwnSyncContext, options.FlowExecutionContext) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (minThreadCount < 0) { throw new ArgumentOutOfRangeException(nameof(minThreadCount)); } if (maxThreadCount <= 0 || maxThreadCount >= 4096) { throw new ArgumentOutOfRangeException(nameof(maxThreadCount), "maxThreadCount should be in range [0, 4096)"); } if (maxThreadCount < minThreadCount) { throw new ArgumentOutOfRangeException(nameof(maxThreadCount), "maxThreadCount should be greater than minThreadCount"); } if (options.MaxQueueCapacityExtension < 0) { throw new ArgumentOutOfRangeException(nameof(options.MaxQueueCapacityExtension)); } if (options.ManagementProcessPeriod <= 0) { throw new ArgumentOutOfRangeException(nameof(options.ManagementProcessPeriod)); } _minThreadCount = minThreadCount; _maxThreadCount = maxThreadCount; _fastSpawnThreadCountLimit = Math.Max(_minThreadCount, Math.Min(_maxThreadCount, FastSpawnThreadCountLimit)); _reasonableThreadCount = Math.Max(_minThreadCount, Math.Min(_maxThreadCount, ReasonableThreadCount)); _managementProcessPeriod = options.ManagementProcessPeriod; _maxQueueCapacityExtension = options.MaxQueueCapacityExtension; _noWorkItemTrimPeriod = options.NoWorkItemTrimPeriod >= 0 ? options.NoWorkItemTrimPeriod : -1; _throughoutTracker = new ExecutionThroughoutTrackerUpDownCorrection(_maxThreadCount, _reasonableThreadCount); _wasSomeProcessByThreadsFlag = false; _dieSlotActiveFullThreadCountCombination = 0; _extThreadBlocker = new PartialThreadBlocker(0); Qoollo.Turbo.Threading.ServiceStuff.ManagementThreadController.Instance.RegisterCallback(ManagementThreadProc); FillPoolUpTo(minThreadCount); }
/// <summary> /// <see cref="DynamicThreadPool"/> constructor /// </summary> /// <param name="minThreadCount">Minimum number of threads that should always be in pool</param> /// <param name="maxThreadCount">Maximum number of threads in pool</param> /// <param name="queueBoundedCapacity">The bounded size of the work items queue (if less or equal to 0 then no limitation)</param> /// <param name="name">The name for this instance of ThreadPool and for its threads</param> /// <param name="isBackground">Whether or not threads are a background threads</param> /// <param name="options">Additional thread pool creation parameters</param> public DynamicThreadPool(int minThreadCount, int maxThreadCount, int queueBoundedCapacity, string name, bool isBackground, DynamicThreadPoolOptions options) : this(options ?? DynamicThreadPoolOptions.Default, minThreadCount, maxThreadCount, queueBoundedCapacity, name, isBackground) { }