private static void SaleTicketThread1() { while (true) { try { Monitor.Enter(obj);//加锁 Thread.Sleep(1); if (tickets > 0)//tickets为多个线程的共用资源 { Thread.Sleep(500); Console.WriteLine("线程1出票:" + tickets--); } else break; } finally { Monitor.Exit(obj);//解锁,必须,否则可能死锁 } } }