My q is will the code be stuck at ... untill locker becomes free ?
Yes, but the lock can be released by exiting a lock() {}
block OR by entering a Wait()
.
after Monitor.Pulse(locker); what will be following sequence of execution ?
In your code the sequence will most likely be:
Thread(pulseWaitFun).Start();
lock (locker)
, uncontested so the lock is immediately grantedMonitor.Pulse(locker);
, the Pulse is wasted because nobody is waiting.- exit
lock()
in the main method - The 2nd Thread starts executing...
You probably want a Thread.Sleep(100)
inside Main(), after starting the Thread.