public TestTaskScheduler(int threadCount, SimpleThreadPool threadPool = null) { threadPool = threadPool ?? CachingSimpleThreadPool.Instance; MaximumConcurrencyLevel = threadCount; lock (_lock) { _activeThreadCount = threadCount; } _events = Enumerable.Range(0, threadCount).Select(_ => new AutoResetEvent(false)).ToArray(); _runEvent = new AutoResetEvent(false); _threads = Enumerable.Range(0, threadCount).Select(i => threadPool.Start(() => RunThread(_events[i]))).ToArray(); }
private readonly LinkedList <Task> _taskQueue = new LinkedList <Task>(); // All tasks that need executing. public TestTaskScheduler(int threadCount, SimpleThreadPool threadPool = null) { _disposeCts = new CancellationTokenSource(); _disposeToken = _disposeCts.Token; MaximumConcurrencyLevel = threadCount; _threadPool = threadPool ?? DefaultSimpleThreadPool.Instance; _threadEvents = new AutoResetEvent[threadCount]; _threadCompletionTasks = new Task[threadCount]; _threadExecutingTasks = new Task[threadCount]; _threadWaiting = new Task[threadCount]; for (int i = 0; i < threadCount; i++) { int threadIndex = i; _threadExecutingTasks[i] = null; _threadWaiting[i] = null; var ev = new AutoResetEvent(false); _threadEvents[i] = ev; _threadCompletionTasks[i] = _threadPool.Start(() => RunThread(threadIndex, ev)); _readyThreadIndexes.Enqueue(i); } }