Ejemplo n.º 1
0
 public static int Main(String[] args) {
  Console.WriteLine("CO_Mutex2.cs ...");
  gM1 = new Mutex(true,"MyMutex");
  gM2 = new Mutex(true);
  CO_Mutex2 tm = new CO_Mutex2();
  Console.WriteLine(" - Main Owns gM1 and gM2");
  Thread t1= new Thread(new ThreadStart(tm.T1start));
  Thread t2= new Thread(new ThreadStart(tm.T2start));
  Thread t3= new Thread(new ThreadStart(tm.T3start));
  Thread t4= new Thread(new ThreadStart(tm.T4start));
  t1.Start();
  t2.Start();
  t3.Start();
  t4.Start();
  Thread.Sleep(2000);
  Console.WriteLine(" - Main releases gM1");
  gM1.ReleaseMutex();
  Thread.Sleep(1000);
  Console.WriteLine(" - Main releases gM2");
  gM2.ReleaseMutex();
  AutoResetEvent[] evs = new AutoResetEvent[4];
  evs[0] = Event1;
  evs[1] = Event2;
  evs[2] = Event3;
  evs[3] = Event4;
  WaitHandle.WaitAll(evs);
  Console.WriteLine("... CO_Mutex2.cs");
  return 0;
 }
Ejemplo n.º 2
0
    public static int Main(String[] args)
    {
        Console.WriteLine("CO_Mutex2.cs ...");
        gM1 = new Mutex(true, "MyMutex");
        gM2 = new Mutex(true);
        CO_Mutex2 tm = new CO_Mutex2();

        Console.WriteLine(" - Main Owns gM1 and gM2");
        Thread t1 = new Thread(new ThreadStart(tm.T1start));
        Thread t2 = new Thread(new ThreadStart(tm.T2start));
        Thread t3 = new Thread(new ThreadStart(tm.T3start));
        Thread t4 = new Thread(new ThreadStart(tm.T4start));

        t1.Start();
        t2.Start();
        t3.Start();
        t4.Start();
        Thread.Sleep(2000);
        Console.WriteLine(" - Main releases gM1");
        gM1.ReleaseMutex();
        Thread.Sleep(1000);
        Console.WriteLine(" - Main releases gM2");
        gM2.ReleaseMutex();
        AutoResetEvent[] evs = new AutoResetEvent[4];
        evs[0] = Event1;
        evs[1] = Event2;
        evs[2] = Event3;
        evs[3] = Event4;
        WaitHandle.WaitAll(evs);
        Console.WriteLine("... CO_Mutex2.cs");
        return(0);
    }