One .NET question. Lets assume that a thread has the lock on an object
and performs a
Monitor::Pulse(obj);
and with that it returns another thread on this object in the running
state, what happens?
Does the other thread become blocked, and while it is in this blocked
state, does it consume processor time (like an infinite loop for example)?
>One .NET question. Lets assume that a thread has the lock on an object
>and performs a
[quoted text clipped - 3 lines]
>and with that it returns another thread on this object in the running
>state, what happens?
According to the Monitor.Pulse documentation:
"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."
The "other" thread is moved to the ready queue, not set running.
>Does the other thread become blocked, and while it is in this blocked
>state, does it consume processor time (like an infinite loop for example)?
So the thread issuing the Pulse continues to run until it releases the lock,
at which point, the thread at the head of the ready queue for the syncobject
acquires it and is scheduled to run.

Signature
Doug Harrison
Microsoft MVP - Visual C++
Ioannis Vranos - 13 Oct 2004 02:15 GMT
> According to the Monitor.Pulse documentation:
>
[quoted text clipped - 12 lines]
> at which point, the thread at the head of the ready queue for the syncobject
> acquires it and is scheduled to run.
Thanks for the answer. Those threads in the ready queue do not use any
processor time, right?

Signature
Ioannis Vranos
Doug Harrison [MVP] - 13 Oct 2004 02:32 GMT
>Thanks for the answer. Those threads in the ready queue do not use any
>processor time, right?
They're not running, so that's correct. Of course, the OS scheduler spends
some time deciding who gets to run, but that's normally of no concern.

Signature
Doug Harrison
Microsoft MVP - Visual C++
Ioannis Vranos - 13 Oct 2004 02:51 GMT
>>Thanks for the answer. Those threads in the ready queue do not use any
>>processor time, right?
>
> They're not running, so that's correct. Of course, the OS scheduler spends
> some time deciding who gets to run, but that's normally of no concern.
OK, thanks a lot.

Signature
Ioannis Vranos