public void TestGetWaitingThreadsNRE() { Mutex sync = new Mutex(); try { sync.GetWaitingThreads(null); ShouldThrow(); } catch (NullReferenceException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestGetWaitingThreadsTSE() { Mutex sync = new Mutex(); AbstractQueuedSynchronizer.ConditionObject c = (sync.NewCondition()); try { sync.GetWaitingThreads(c); ShouldThrow(); } catch (ThreadStateException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestGetWaitingThreads() { Mutex sync = new Mutex(); AbstractQueuedSynchronizer.ConditionObject c = sync.NewCondition(); Pair data = new Pair(sync, c); Thread t1 = new Thread(TestGetWaitingThreadsRunnable1); Thread t2 = new Thread(TestGetWaitingThreadsRunnable2); try { sync.Acquire(1); Assert.IsTrue(sync.GetWaitingThreads(c).IsEmpty()); sync.Release(1); t1.Start(data); Thread.Sleep(SHORT_DELAY_MS); t2.Start(data); Thread.Sleep(SHORT_DELAY_MS); sync.Acquire(1); Assert.IsTrue(sync.HasWaiters(c)); Assert.IsTrue(sync.GetWaitingThreads(c).Contains(t1)); Assert.IsTrue(sync.GetWaitingThreads(c).Contains(t2)); c.SignalAll(); sync.Release(1); Thread.Sleep(SHORT_DELAY_MS); sync.Acquire(1); Assert.IsFalse(sync.HasWaiters(c)); Assert.IsTrue(sync.GetWaitingThreads(c).IsEmpty()); sync.Release(1); t1.Join(SHORT_DELAY_MS); t2.Join(SHORT_DELAY_MS); Assert.IsFalse(t1.IsAlive); Assert.IsFalse(t2.IsAlive); } catch (Exception e) { UnexpectedException(e); } }