Example #1
0
    public void Target <U>(object p)
    {
        //dummy line to avoid warnings
        Test_thread22.Eval(typeof(U) != p.GetType());
        ManualResetEvent evt = (ManualResetEvent)p;

        Interlocked.Increment(ref Test_thread22.Xcounter);
        evt.Set();
    }
Example #2
0
    public static void DelegateTest <U>()
    {
        IGen <string> obj = new GenString();
        ThreadStart   d   = new ThreadStart(obj.Target <U>);


        d();
        Test_thread22.Eval(Test_thread22.Xcounter == 1);
        Test_thread22.Xcounter = 0;
    }
Example #3
0
    public static void ThreadPoolTest <U>()
    {
        ManualResetEvent evt = new ManualResetEvent(false);

        IGen <double> obj = new GenDouble();

        TimerCallback tcb   = new TimerCallback(obj.Target <U>);
        Timer         timer = new Timer(tcb, evt, Test_thread22.delay, Test_thread22.period);

        evt.WaitOne();
        timer.Dispose();
        Test_thread22.Eval(Test_thread22.Xcounter >= Test_thread22.nThreads);
        Test_thread22.Xcounter = 0;
    }
Example #4
0
    public static void ThreadPoolTest <U>()
    {
        Thread[]      threads = new Thread[Test_thread22.nThreads];
        IGen <string> obj     = new GenString();

        for (int i = 0; i < Test_thread22.nThreads; i++)
        {
            threads[i] = new Thread(new ThreadStart(obj.Target <U>));
            threads[i].Start();
        }

        for (int i = 0; i < Test_thread22.nThreads; i++)
        {
            threads[i].Join();
        }

        Test_thread22.Eval(Test_thread22.Xcounter == Test_thread22.nThreads);
        Test_thread22.Xcounter = 0;
    }
Example #5
0
    public static void ThreadPoolTest <U>()
    {
        ManualResetEvent[] evts = new ManualResetEvent[Test_thread22.nThreads];
        WaitHandle[]       hdls = new WaitHandle[Test_thread22.nThreads];

        for (int i = 0; i < Test_thread22.nThreads; i++)
        {
            evts[i] = new ManualResetEvent(false);
            hdls[i] = (WaitHandle)evts[i];
        }

        IGen <double> obj = new GenDouble();

        for (int i = 0; i < Test_thread22.nThreads; i++)
        {
            WaitCallback cb = new WaitCallback(obj.Target <U>);
            ThreadPool.QueueUserWorkItem(cb, evts[i]);
        }

        WaitHandle.WaitAll(hdls);
        Test_thread22.Eval(Test_thread22.Xcounter == Test_thread22.nThreads);
        Test_thread22.Xcounter = 0;
    }
Example #6
0
 public void Target <U>()
 {
     //dummy line to avoid warnings
     Test_thread22.Eval(typeof(U) != null);
     Interlocked.Increment(ref Test_thread22.Xcounter);
 }