private void InterruptedLock()
 {
     Assert.Throws <ThreadInterruptedException>(delegate
     {
         _lock.LockInterruptibly();
     });
 }
        [Test] public void LockInterruptiblySucceedsWhenUnlockedElseIsInterruptible([Values(true, false)] bool isFair)
        {
            _lock = new ReentrantLock(isFair);
            _lock.LockInterruptibly();
            var threads = ThreadManager.StartAndAssertRegistered("T",
                                                                 InterruptedLock,
                                                                 delegate { using (_lock.LockInterruptibly()) { } },
                                                                 delegate { using (_lock.LockInterruptibly()) { } });

            threads[0].Interrupt();
            ThreadManager.JoinAndVerify(threads[0]);
            Assert.IsTrue(_lock.IsLocked);
            Assert.IsTrue(_lock.IsHeldByCurrentThread);
            _lock.Unlock();
            ThreadManager.JoinAndVerify();
        }
        [Test] public void GetHoldCountReturnsNumberOfRecursiveHolds([Values(true, false)] bool isFair)
        {
            _lock = new ReentrantLock(isFair);

            RecursiveHolds(delegate { _lock.Lock(); });
            RecursiveHolds((delegate
            {
                Assert.IsTrue(_lock.TryLock());
            }));
            RecursiveHolds(delegate
            {
                Assert.IsTrue(_lock.TryLock(Delays.Short));
            });
            RecursiveHolds(delegate { _lock.LockInterruptibly(); });
        }
        [Test] public void TimedTryLockAllSucceedsFromMultipleThreads([Values(true, false)] bool isFair)
        {
            _lock = new ReentrantLock(isFair);
            _lock.LockInterruptibly();
            ThreadStart action =
                delegate
            {
                Assert.IsTrue(_lock.TryLock(Delays.Long));
                try
                {
                    Thread.Sleep(Delays.Short);
                }
                finally
                {
                    _lock.Unlock();
                }
            };

            ThreadManager.StartAndAssertRegistered("T", action, action);
            Assert.IsTrue(_lock.IsLocked);
            Assert.IsTrue(_lock.IsHeldByCurrentThread);
            _lock.Unlock();
            ThreadManager.JoinAndVerify();
        }