Exemplo n.º 1
0
        private static void Demo3()
        {
            int          numThreads = 7;
            object       synch      = new object();
            List <Multi> multis     = new List <Multi>();

            Monitor.Enter(synch);

            for (int i = 0; i < numThreads; i++)
            {
                Multi m = new Multi(synch, i + 1);
                multis.Add(m);
                m.Start();
            }

            Thread.Sleep(2000);

            Monitor.Exit(synch);

            for (int i = 0; i < numThreads; i++)
            {
                multis[i].Thread.Join();
            }
        }
Exemplo n.º 2
0
        private static void Demo3()
        {
            int numThreads = 7;
            object synch = new object();
            List<Multi> multis = new List<Multi>();

            Monitor.Enter(synch);

            for (int i = 0; i < numThreads; i++)
            {
                Multi m = new Multi(synch, i + 1);
                multis.Add(m);
                m.Start();
            }

            Thread.Sleep(2000);

            Monitor.Exit(synch);

            for (int i = 0; i < numThreads; i++)
            {
                multis[i].Thread.Join();
            }
        }