G
Guest
Here is a quote from MSDN regarding the behavior of Monitor.Pulse:
“The thread that currently owns the lock on the specified object invokes
this method to signal the next thread in line for the lock. Upon receiving
the pulse, the waiting thread is moved to the ready queue. When the thread
that invoked Pulse releases the lock, the next thread in the ready queue
(which is not necessarily the thread that was pulsed) acquires the lock.â€
Evidence shows that when thread A pulses an object for which thread B is
waiting within a locked region of that object, and then thread A leaves the
locked region of that object, thread A can repossess the object's locked
region before thread B demonstrates ownership of that region. This seems to
contradict MSDN notes above.
Given:
Thread B performs: lock(x) { ... Monitor.Wait(x) ... }
Thread A performs: while(1) { lock(x) { ... Monitor.Pulse(x) ... } }
Thread B will be starved out waiting for the mutex on x and there is no
sequencing guarantee that thread B will finish executing before thread A
reaquires the mutex. Is this a bug or intended behavior?
“The thread that currently owns the lock on the specified object invokes
this method to signal the next thread in line for the lock. Upon receiving
the pulse, the waiting thread is moved to the ready queue. When the thread
that invoked Pulse releases the lock, the next thread in the ready queue
(which is not necessarily the thread that was pulsed) acquires the lock.â€
Evidence shows that when thread A pulses an object for which thread B is
waiting within a locked region of that object, and then thread A leaves the
locked region of that object, thread A can repossess the object's locked
region before thread B demonstrates ownership of that region. This seems to
contradict MSDN notes above.
Given:
Thread B performs: lock(x) { ... Monitor.Wait(x) ... }
Thread A performs: while(1) { lock(x) { ... Monitor.Pulse(x) ... } }
Thread B will be starved out waiting for the mutex on x and there is no
sequencing guarantee that thread B will finish executing before thread A
reaquires the mutex. Is this a bug or intended behavior?