public ThreadPool(int?threadCount = null) { semaphore = new SemaphoreW(spinCountParam: 70); WorkerThreadsCount = threadCount ?? (Environment.ProcessorCount == 1 ? 1 : Environment.ProcessorCount - 1); leftToDispose = WorkerThreadsCount; for (int i = 0; i < WorkerThreadsCount; i++) { NewWorker(); } }
/// <summary> /// Initializes a new instance of the <see cref="ThreadPool"/> class. /// </summary> /// <param name="threadCount"> /// The number of worker threads to spawn. Specify <c>null</c> to decide the count based on the number of processors in the system. /// </param> public ThreadPool(int?threadCount = null) { semaphore = new SemaphoreW(spinCountParam: 70); WorkerThreadsCount = threadCount ?? (isSingleCore ? 1 : Environment.ProcessorCount - 1); for (int i = 0; i < WorkerThreadsCount; i++) { CreateWorkerThread(); } }
public ThreadPool(int?threadCount = null) { WorkerThreadsCount = threadCount ?? Environment.ProcessorCount; for (int i = 0; i < WorkerThreadsCount; i++) { NewWorker(); } // Benchmark this on multiple computers at different work frequency const int SpinDuration = 140; semaphore = new SemaphoreW(0, SpinDuration); }