Synchronizing with Monitor
I have found a code snippet that looks like this:
var signal = new object();
var signalSet = false;
// Thread 1
lock (signal)
{
while (!signalSet)
{
Monitor.Wait(signal);
}
}
// Thread 2
lock (signal)
{
signalSet = true;
Monitor.Pulse(signal);
}
I am confused about the while loop. What does it accomplish? Does a simple "if" do the same here?
Found at:
https://stackoverflow.com/questions/1355398/monitor-vs-waithandle-based-thread-sync
Stack Overflow
Monitor vs WaitHandle based thread sync
I was under the impression, after reading this article that it is better to use Monitor/Lock for thread synchronisation as it does not use native resources
Specific quote (from page 5 of the articl...
0 Replies