public void TestLockInterruptibly2() { ReentrantLock locker = new ReentrantLock(); try { locker.LockInterruptibly(); } catch (Exception e) { UnexpectedException(e); } Thread t = new Thread(InterruptedLockRunnable); try { t.Start(locker); t.Interrupt(); Assert.IsTrue(locker.IsLocked); Assert.IsTrue(locker.IsHeldByCurrentThread); t.Join(); } catch (Exception e) { UnexpectedException(e); } }
private void InterruptibleLockRunnable(object state) { ReentrantLock locker = state as ReentrantLock; try { locker.LockInterruptibly(); } catch (ThreadInterruptedException) { } }
public void TestLockInterruptibly2() { ReentrantLock locker = new ReentrantLock(); try { locker.LockInterruptibly(); } catch(Exception e) { UnexpectedException(e); } Thread t = new Thread(InterruptedLockRunnable); try { t.Start(locker); t.Interrupt(); Assert.IsTrue(locker.IsLocked); Assert.IsTrue(locker.IsHeldByCurrentThread); t.Join(); } catch(Exception e) { UnexpectedException(e); } }