public void GetWaitingThreadsChokesWhenNotLocked(bool isFair) { PublicReentrantLock myLock = new PublicReentrantLock(isFair); ICondition c = (myLock.NewCondition()); myLock.GetWaitingThreadsPublic(c); }
public void TestGetQueuedThreads() { PublicReentrantLock locker = new PublicReentrantLock(); Thread t1 = new Thread(InterruptedLockRunnable); Thread t2 = new Thread(InterruptibleLockRunnable); try { Assert.IsTrue(locker.GetAtQueuedThreads().IsEmpty()); locker.Lock(); Assert.IsTrue(locker.GetAtQueuedThreads().IsEmpty()); t1.Start(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t1)); t2.Start(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t1)); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t2)); t1.Interrupt(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsFalse(locker.GetAtQueuedThreads().Contains(t1)); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t2)); locker.UnLock(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsTrue(locker.GetAtQueuedThreads().IsEmpty()); t1.Join(); t2.Join(); } catch (Exception e) { UnexpectedException(e); } }
public void GetWaitingThreadsChokesWhenNotOwned([Values(true, false)] bool isFair) { PublicReentrantLock myLock = new PublicReentrantLock(isFair); ICondition c = (myLock.NewCondition()); PublicReentrantLock lock2 = new PublicReentrantLock(isFair); lock2.GetWaitingThreadsPublic(c); }
public void TestGetWaitingThreadsNRE() { PublicReentrantLock locker = new PublicReentrantLock(); try { locker.GetWaitingThreads(null); ShouldThrow(); } catch (NullReferenceException) { } catch (Exception e) { UnexpectedException(e); } }
public void GetWaitingThreadsIncludesWaitingThreads(bool isFair) { PublicReentrantLock myLock = new PublicReentrantLock(isFair); ICondition c = myLock.NewCondition(); myLock.Lock(); Assert.That(myLock.GetWaitingThreadsPublic(c).Count, Is.EqualTo(0)); myLock.Unlock(); Thread t1 = ThreadManager.StartAndAssertRegistered( "T1", delegate { myLock.Lock(); Assert.That(myLock.GetWaitingThreadsPublic(c).Count, Is.EqualTo(0)); c.Await(); myLock.Unlock(); }); Thread.Sleep(Delays.Short); Thread t2 = ThreadManager.StartAndAssertRegistered( "T2", delegate { myLock.Lock(); Assert.That(myLock.GetWaitingThreadsPublic(c).Count, Is.Not.EqualTo(0)); c.Await(); myLock.Unlock(); }); Thread.Sleep(Delays.Short); myLock.Lock(); Assert.IsTrue(myLock.HasWaiters(c)); Assert.IsTrue(myLock.GetWaitingThreadsPublic(c).Contains(t1)); Assert.IsTrue(myLock.GetWaitingThreadsPublic(c).Contains(t2)); c.SignalAll(); myLock.Unlock(); Thread.Sleep(Delays.Short); myLock.Lock(); Assert.IsFalse(myLock.HasWaiters(c)); Assert.IsTrue((myLock.GetWaitingThreadsPublic(c).Count == 0)); myLock.Unlock(); ThreadManager.JoinAndVerify(); }
public void TestGetWaitingThreadsTSE() { PublicReentrantLock locker = new PublicReentrantLock(); Condition c = (locker.NewCondition()); try { locker.GetWaitingThreads(c); ShouldThrow(); } catch (ThreadStateException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestGetWaitingThreads() { PublicReentrantLock locker = new PublicReentrantLock(); Condition c = locker.NewCondition(); Pair data = new Pair(locker, c); Thread t1 = new Thread(TestGetWaitingThreadsRunnable1); Thread t2 = new Thread(TestGetWaitingThreadsRunnable2); try { locker.Lock(); Assert.IsTrue(locker.GetWaitingThreads(c).IsEmpty()); locker.UnLock(); t1.Start(data); Thread.Sleep(SHORT_DELAY_MS); t2.Start(data); Thread.Sleep(SHORT_DELAY_MS); locker.Lock(); Assert.IsTrue(locker.HasWaiters(c)); Assert.IsTrue(locker.GetWaitingThreads(c).Contains(t1)); Assert.IsTrue(locker.GetWaitingThreads(c).Contains(t2)); c.SignalAll(); locker.UnLock(); Thread.Sleep(SHORT_DELAY_MS); locker.Lock(); Assert.IsFalse(locker.HasWaiters(c)); Assert.IsTrue(locker.GetWaitingThreads(c).IsEmpty()); locker.UnLock(); t1.Join(SHORT_DELAY_MS); t2.Join(SHORT_DELAY_MS); Assert.IsFalse(t1.IsAlive); Assert.IsFalse(t2.IsAlive); } catch (Exception e) { UnexpectedException(e); } }
public void GetWaitingThreadsChokesOnNullParameter([Values(true, false)] bool isFair) { PublicReentrantLock myLock = new PublicReentrantLock(isFair); myLock.GetWaitingThreadsPublic(null); }
public void TestGetWaitingThreads() { PublicReentrantLock locker = new PublicReentrantLock(); Condition c = locker.NewCondition(); Pair data = new Pair(locker, c); Thread t1 = new Thread(TestGetWaitingThreadsRunnable1); Thread t2 = new Thread(TestGetWaitingThreadsRunnable2); try { locker.Lock(); Assert.IsTrue(locker.GetWaitingThreads(c).IsEmpty()); locker.UnLock(); t1.Start(data); Thread.Sleep(SHORT_DELAY_MS); t2.Start(data); Thread.Sleep(SHORT_DELAY_MS); locker.Lock(); Assert.IsTrue(locker.HasWaiters(c)); Assert.IsTrue(locker.GetWaitingThreads(c).Contains(t1)); Assert.IsTrue(locker.GetWaitingThreads(c).Contains(t2)); c.SignalAll(); locker.UnLock(); Thread.Sleep(SHORT_DELAY_MS); locker.Lock(); Assert.IsFalse(locker.HasWaiters(c)); Assert.IsTrue(locker.GetWaitingThreads(c).IsEmpty()); locker.UnLock(); t1.Join(SHORT_DELAY_MS); t2.Join(SHORT_DELAY_MS); Assert.IsFalse(t1.IsAlive); Assert.IsFalse(t2.IsAlive); } catch (Exception e) { UnexpectedException(e); } }
public void TestGetWaitingThreadsTSE() { PublicReentrantLock locker = new PublicReentrantLock(); Condition c = (locker.NewCondition()); try { locker.GetWaitingThreads(c); ShouldThrow(); } catch (ThreadStateException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestGetWaitingThreadsNRE() { PublicReentrantLock locker = new PublicReentrantLock(); try { locker.GetWaitingThreads(null); ShouldThrow(); } catch (NullReferenceException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestGetQueuedThreads() { PublicReentrantLock locker = new PublicReentrantLock(); Thread t1 = new Thread(InterruptedLockRunnable); Thread t2 = new Thread(InterruptibleLockRunnable); try { Assert.IsTrue(locker.GetAtQueuedThreads().IsEmpty()); locker.Lock(); Assert.IsTrue(locker.GetAtQueuedThreads().IsEmpty()); t1.Start(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t1)); t2.Start(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t1)); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t2)); t1.Interrupt(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsFalse(locker.GetAtQueuedThreads().Contains(t1)); Assert.IsTrue(locker.GetAtQueuedThreads().Contains(t2)); locker.UnLock(); Thread.Sleep(SHORT_DELAY_MS); Assert.IsTrue(locker.GetAtQueuedThreads().IsEmpty()); t1.Join(); t2.Join(); } catch(Exception e) { UnexpectedException(e); } }