public void ThreadFinished() { _finished.Add(RunningThreadId); _enabled.Remove(RunningThreadId); _priority.RemovePriorityOf(RunningThreadId); if (!AllThreadsFinished) { if (_deadlock) { // If there is a deadlock, manually schedule the threads // in turn, so they have the opportunity to throw an exception and exit. // Calling MaybeSwitch() here isn't possible, because there are no // enabled threads to schedule. var unfinished = new ThreadSet(_numThreads); for (int i = 0; i < _numThreads; ++i) { if (!_finished[i]) { RunningThreadId = i; } } } else { MaybeSwitch(); } } }
private void PrepareForScheduling() { _finished = new ThreadSet(_numThreads); _enabled = new ThreadSet(_numThreads); _disabledSince = new ThreadSet[_numThreads]; _scheduledSince = new ThreadSet[_numThreads]; _enabledSince = new ThreadSet[_numThreads]; for (int i = 0; i < _numThreads; ++i) { _disabledSince[i] = new ThreadSet(_numThreads); _enabledSince[i] = new ThreadSet(_numThreads); _scheduledSince[i] = new ThreadSet(_numThreads); _enabled.Add(i); } _waitingOnLock = new object[_numThreads]; _priority = new PriorityRelation(_numThreads); _currentYieldPenalty = 0; _deadlock = false; }
public void ThreadFinishedWaiting() { _enabled.Add(RunningThreadId); _waitingOnLock[RunningThreadId] = null; }