public static void DelegateTest <U>() { ThreadStart d = new ThreadStart(new Gen().Target <U>); d(); Test_thread08.Eval(Test_thread08.Xcounter == 1); Test_thread08.Xcounter = 0; }
public void Target <U>(object p) { //dummy line to avoid warnings Test_thread08.Eval(typeof(U) != p.GetType()); ManualResetEvent evt = (ManualResetEvent)p; Interlocked.Increment(ref Test_thread08.Xcounter); evt.Set(); }
public static void ThreadPoolTest <U>() { ManualResetEvent evt = new ManualResetEvent(false); Gen obj = new Gen(); TimerCallback tcb = new TimerCallback(obj.Target <U>); Timer timer = new Timer(tcb, evt, Test_thread08.delay, Test_thread08.period); evt.WaitOne(); timer.Dispose(); Test_thread08.Eval(Test_thread08.Xcounter >= Test_thread08.nThreads); Test_thread08.Xcounter = 0; }
public static void ThreadPoolTest <U>() { Thread[] threads = new Thread[Test_thread08.nThreads]; Gen obj = new Gen(); for (int i = 0; i < Test_thread08.nThreads; i++) { threads[i] = new Thread(new ThreadStart(obj.Target <U>)); threads[i].Start(); } for (int i = 0; i < Test_thread08.nThreads; i++) { threads[i].Join(); } Test_thread08.Eval(Test_thread08.Xcounter == Test_thread08.nThreads); Test_thread08.Xcounter = 0; }
public static void ThreadPoolTest <U>() { ManualResetEvent[] evts = new ManualResetEvent[Test_thread08.nThreads]; WaitHandle[] hdls = new WaitHandle[Test_thread08.nThreads]; for (int i = 0; i < Test_thread08.nThreads; i++) { evts[i] = new ManualResetEvent(false); hdls[i] = (WaitHandle)evts[i]; } Gen obj = new Gen(); for (int i = 0; i < Test_thread08.nThreads; i++) { WaitCallback cb = new WaitCallback(obj.Target <U>); ThreadPool.QueueUserWorkItem(cb, evts[i]); } WaitHandle.WaitAll(hdls); Test_thread08.Eval(Test_thread08.Xcounter == Test_thread08.nThreads); Test_thread08.Xcounter = 0; }
public void Target <U>() { //dummy line to avoid warnings Test_thread08.Eval(typeof(U) != null); Interlocked.Increment(ref Test_thread08.Xcounter); }