示例#1
0
        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);
            }
        }
示例#2
0
        private void InterruptibleLockRunnable(object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            try
            {
                locker.LockInterruptibly();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
示例#3
0
        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);
            }
        }