public void AwaitUninterruptibly() { ReentrantReadWriteLock myLock = new ReentrantReadWriteLock(); ICondition c = myLock.WriterLock.NewCondition(); UninterruptableThread thread = new UninterruptableThread(myLock.WriterLock, c); thread.InternalThread.Start(); while (!thread.lockStarted) { Thread.Sleep(new TimeSpan(0, 0, 0, 0, 100)); } myLock.WriterLock.Lock(); try { thread.InternalThread.Interrupt(); thread.canAwake = true; c.Signal(); } finally { myLock.WriterLock.Unlock(); } thread.InternalThread.Join(); Assert.IsTrue(thread.interrupted); Assert.IsFalse(thread.InternalThread.IsAlive); }
[Test] public void AwaitUninterruptiblyCannotBeInterrupted([Values(true, false)] bool isFair) { _lock = new ReentrantLock(isFair); ICondition c = _lock.NewCondition(); UninterruptableThread thread = new UninterruptableThread(_lock, c); thread.InternalThread.Start(); while (!thread.LockStarted) { Thread.Sleep(100); } _lock.Lock(); try { thread.InternalThread.Interrupt(); thread.CanAwake = true; c.Signal(); } finally { _lock.Unlock(); } ThreadManager.JoinAndVerify(thread.InternalThread); Assert.IsTrue(thread.Interrupted); }