I am developing an app for windows phone 7.Now I have 2 threads.
thread 1
lock(somelock)
{
//does some work
Monitor.Wait();
//Does some work
}
thread 2
lock(somelock)
{
//does some work
Monitor.Signal();
//does some work;
}
Now I want to know whether Monitor.wait() signals the other thread.
A thread that fails to get a lock is held in the ready queue. If the thread with the lock calls Wait, then it yields the lock and any threads in the ready-queue are eligible to be activated, obtaining the lock. So in a way they are activated, but they aren’t “pulsed”, if that is what you mean by signalled.
By contrast, the thread that voluntarily called Wait is in a separate queue; it doesn’t become activated just by a thread yielding the lock; the only way that thread gets back into the ready queue is if either a thread with the lock calls Pulse/PulseAll, or the timeout occurs. Note that Pulse/PulseAll do not yield the lock – they just more a thread/threads from the sleeping queue to the ready-queue. The lock in the second example is only yielded when leaving the
lockstatement. As a consequence of this, note that the “does some work” after the Pulse (Signal in your example) is still done while holding an exclusive lock (in effect, you might as well move the Pulse to the end of the lock statement).