|
|
От: |
Александр Малафеев
|
http://www.meet-tech.com |
| Дата: | 21.03.08 09:34 | ||
| Оценка: | |||
class Program
{
static void Main(string[] args)
{
Thread t1 = new Thread(ThreadProc);
Thread t2 = new Thread(ThreadProc);
Thread t3 = new Thread(ThreadProc);
t1.Start();
t2.Start();
t3.Start();
t1.Join();
t2.Join();
t3.Join();
}
public static object sync1 = new object();
public static object sync2 = new object();
public static void ThreadProc()
{
if (Monitor.TryEnter(sync1))
{
try
{
DoSmth();
lock (sync2)
{
Monitor.PulseAll(sync2);
}
}
finally
{
Monitor.Exit(sync1);
}
}
else
{
lock (sync2)
{
Monitor.Wait(sync2);
}
}
}
public static void DoSmth()
{
Console.WriteLine("i'm here");
}
}