コード例 #1
0
        public void WriteLockIsHeld__AnotherThreadBlocksOnReadLockAcquisition()
        {
            var l = new ReaderWriterLockSlimEx();

            using (l.AcquireWriteLock())
            {
                Task.Factory.StartNew(() =>
                    {
                        var acquisition = (IReadLockAcquisition)null;
                        
                        if(l.TryAcquireReadLock(TEST_DefaultTimeout, out acquisition))
                        {
                            // should not get here
                            Assert.Fail();
                        }
                    }).Wait();
            }
        }
コード例 #2
0
        public void SupportsRecursion__WriteLockIsHeld__AnotherLockCanBeAcquired()
        {
            var l = new ReaderWriterLockSlimEx(LockRecursionPolicy.SupportsRecursion);

            IReadLockAcquisition r;
            IUpgradeableReadLockAcquisition ur;
            IWriteLockAcquisition w;

            var a1 = l.AcquireReadLock();
            var a2 = l.TryAcquireReadLock(TEST_DefaultTimeout, out r);
            var a3 = l.TryAcquireUpgradeableReadLock(TEST_DefaultTimeout, out ur);
            var a4 = l.TryAcquireWriteLock(TEST_DefaultTimeout, out w);

            Assert.IsTrue(a2);
            Assert.IsFalse(a3);
            Assert.IsFalse(a4);
        }