Exemple #1
0
        private static HashSet <Guid> ThreadsWaitingForMyLocks(Guid owner, PessimisticLockFactory locksInUse)
        {
            var waitingThreads = new HashSet <Guid>();

            locksInUse._locks.Values.Where(x => x.CurrentOwner == owner)
            .ToList()
            .ForEach(disposableLock => disposableLock.Waiters
                     .Where(x => waitingThreads.Add(x))
                     .ForEach(threadId => ThreadsWaitingForMyLocks(threadId, locksInUse).ForEach(x => waitingThreads.Add(x))));

            return(waitingThreads);
        }
Exemple #2
0
 private void CheckForDeadlock()
 {
     if (!IsOwner && IsLocked)
     {
         foreach (var threadId in PessimisticLockFactory.ThreadsWaitingForMyLocks(CurrentThreadId, PessimisticLockFactory.Instance))
         {
             if (CurrentOwner == threadId)
             {
                 throw new DeadlockException("An imminent deadlock was detected while attempting to acquire a lock");
             }
         }
     }
 }