.NET Multithreading question

  • Thread starter Thread starter Ioannis Vranos
  • Start date Start date
I

Ioannis Vranos

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)?
 
Ioannis said:
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?

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.
 
Doug said:
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.




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.


Thanks for the answer. Those threads in the ready queue do not use any
processor time, right?
 
Ioannis said:
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.
 
Doug said:
Ioannis Vranos wrote:




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.
 
Back
Top