示例#1
0
        static int Main(string[] args)
        {
            int rValue = 0;
            Thread[] threads = new Thread[100];
            ThreadSafe tsi = new ThreadSafe();
            for (int i = 0; i < threads.Length - 1; i++)
            {
                if (i % 2 == 0)
                    threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerA));
                else
                    threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerB));
                threads[i].Start();
            }
            threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker));
            threads[threads.Length - 1].Start();
            tsi.Signal();

            for (int i = 0; i < threads.Length; i++)
                threads[i].Join();

            if (tsi.Pass)
                rValue = 100;
            Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
            return rValue;
        }
示例#2
0
        static int Main(string[] args)
        {
            int rValue = 0;

            Thread[]   threads = new Thread[100];
            ThreadSafe tsi     = new ThreadSafe();

            for (int i = 0; i < threads.Length - 1; i++)
            {
                if (i % 2 == 0)
                {
                    threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerA));
                }
                else
                {
                    threads[i] = new Thread(new ThreadStart(tsi.ThreadWorkerB));
                }
                threads[i].Start();
            }
            threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker));
            threads[threads.Length - 1].Start();
            tsi.Signal();

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

            if (tsi.Pass)
            {
                rValue = 100;
            }
            Console.WriteLine("Test {0}", rValue == 100 ? "Passed" : "Failed");
            return(rValue);
        }