Untitled
unknown
plain_text
2 years ago
1.2 kB
2
Indexable
using System; using System.Threading; class Program { static void Main(string[] args) { int n = 15; AutoResetEvent t1Event = new AutoResetEvent(false); AutoResetEvent t2Event = new AutoResetEvent(false); AutoResetEvent t3Event = new AutoResetEvent(false); Thread t1 = new Thread(() => { for (int i = 1; i <= n; i += 3) { Console.WriteLine("Thread 1: " + i); t2Event.Set(); t1Event.WaitOne(); } }); Thread t2 = new Thread(() => { for (int i = 2; i <= n; i += 3) { t2Event.WaitOne(); Console.WriteLine("Thread 2: " + i); t3Event.Set(); } }); Thread t3 = new Thread(() => { for (int i = 3; i <= n; i += 3) { t3Event.WaitOne(); Console.WriteLine("Thread 3: " + i); t1Event.Set(); } }); t1.Start(); t2.Start(); t3.Start(); Console.ReadKey(); } }
Editor is loading...