C#线程
using System.Threading;
public static Object synchronizeVariable = "locking variable";
static void Main() { Thread[] threads = new Thread[2]; for (int count = 0; count < threads.Length; count++) { threads[count] = new Thread(new ThreadStart(Count)); Console.WriteLine("before start"); threads[count].Start(); Console.WriteLine("after start"); } Console.ReadLine(); } public static void Count() { lock (synchronizeVariable) { for (int count = 1; count <= 5; count++) { Console.Write(count + " "); Monitor.PulseAll(synchronizeVariable); if (count < 5) Monitor.Wait(synchronizeVariable); }
} } 本文出自 51CTO.COM技术博客 |


glen2224
博客统计信息
热门文章
最新评论
友情链接