private void checkAgainst(ThreadLocksTrack subject, ThreadLocksTrack target, int subjectThread, int targetThread) { var(obj, locks) = subject.Report .Where( x => x.Value .Select(y => y.AcqusitionState) .Contains(ThreadLocksTrack.AcqusitionState.Intent)) .Single(); if (target.Report.ContainsKey(obj) == false) { // Target doesn't contain intended object // so no deadlock can exist. return; } var(tObj, tLocks) = target.Report .Where( x => x.Value .Select(y => y.AcqusitionState) .Contains(ThreadLocksTrack.AcqusitionState.Intent)) .Single(); if (obj == tObj) { // The target also intents to unlock the object. return; } if (subject.Report.ContainsKey(tObj) == false) { // The taget intents to unlock object that is not locked by subject. return; } throw new DeadlockException( subjectThread, obj, locks.Single(x => x.AcqusitionState == ThreadLocksTrack.AcqusitionState.Intent).LockState, subject.Report[tObj].Last().LockState, targetThread, tObj, tLocks.Single(x => x.AcqusitionState == ThreadLocksTrack.AcqusitionState.Intent).LockState, target.Report[obj].Last().LockState); }
private ThreadLocksTrack getTrack(int threadId) { if (threadsLocksTrack.TryGetValue(threadId, out var track) == false) { track = new ThreadLocksTrack(); #if DEBUG if (threadsLocksTrack.TryAdd(threadId, track) == false) { // TODO: remove when proven that no collisions can occur. throw new InvalidOperationException("Thread id collision."); } #else threadsLocksTrack.TryAdd(threadId, track); #endif } return(track); }