public void CheckWhetherThreadsUsingThreadPoolAreSynchronized() { CriticalSectionExample m_ThreadsExample = new CriticalSectionExample(); m_ThreadsExample.StartThreadsUsingThreadPool(true); Assert.IsTrue(m_ThreadsExample.IsConsistent); }
public void CheckWhetherThreadsAreNotSynchronized() { CriticalSectionExample m_ThreadsExample = new CriticalSectionExample(); m_ThreadsExample.StartThreads(false); Assert.IsFalse(m_ThreadsExample.IsConsistent); }
public void NoMonitorMethodTest() { CriticalSectionExample m_ThreadsExample = new CriticalSectionExample(); ThreadPool.QueueUserWorkItem(m_ThreadsExample.NoMonitorMethod); ThreadPool.QueueUserWorkItem(m_ThreadsExample.NoMonitorMethod); Thread.Sleep(SleepTime); // wait for threads Assert.AreNotEqual(2 * 1000000, m_ThreadsExample.LockedNumber); }
public void WaitPulseMethodsTest() { CriticalSectionExample m_ThreadsExample = new CriticalSectionExample(); ThreadPool.QueueUserWorkItem(m_ThreadsExample.WaitMethod); Thread.Sleep(SleepTime); ThreadPool.QueueUserWorkItem(m_ThreadsExample.PulseMethod); Thread.Sleep(SleepTime); // wait for threads Assert.AreEqual(0, m_ThreadsExample.LockedNumber); }
public void MonitorMethodWithTimeoutTest() { CriticalSectionExample m_ThreadsExample = new CriticalSectionExample(); object tab = new bool[] { false }; ThreadPool.QueueUserWorkItem(m_ThreadsExample.MonitorMethodWithTimeout, tab); ThreadPool.QueueUserWorkItem(m_ThreadsExample.MonitorMethodWithTimeout, tab); Assert.AreEqual(false, ((bool[])tab)[0]); Thread.Sleep(2000); // 2 seconds - wait the timeout Assert.AreEqual(true, ((bool[])tab)[0]); }
public void MonitorMethodTest() { CriticalSectionExample m_ThreadsExample = new CriticalSectionExample(); ThreadPool.QueueUserWorkItem(m_ThreadsExample.MonitorMethod); ThreadPool.QueueUserWorkItem(m_ThreadsExample.MonitorMethod); Thread.Sleep(SleepTime); // wait for threads const int _expectedCycles = 2 * 1000000; // twice the number of iterations Assert.AreEqual(_expectedCycles, m_ThreadsExample.LockedNumber); }
public void TestInitialize() { m_ThreadsExample = new CriticalSectionExample(); }