threading waiting on message queues

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hello,

Here is my challenge.

I have a thread awaiting events being sent via Queue. Currently I am
checking the count and if there is a count, Dequeue() the next object
and process it. By design, however, this is inefficient usage of CPU
clocks.

A more efficient usage could be to wrap Monitor::Wait() and
Monitor::Pulse() events. If Monitor operations like I think it does, I
should be able to Wait() efficiently forever for the next event to
arrive and before I Dequeue() it. And use Pulse() to signal when a
next event has been Enqueue()d.

Does Wait() wait efficiently for the next pulse to arrive?
Are pulses queued cumulatively?
Or is there only one state (pulsed or not)?
(Not insurmountable if this cannot happen.)

Best regards,
Michael Powell
 
Mike said:
Hello,

Here is my challenge.

I have a thread awaiting events being sent via Queue. Currently I am
checking the count and if there is a count, Dequeue() the next object
and process it. By design, however, this is inefficient usage of CPU
clocks.

A more efficient usage could be to wrap Monitor::Wait() and
Monitor::Pulse() events. If Monitor operations like I think it does, I
should be able to Wait() efficiently forever for the next event to
arrive and before I Dequeue() it. And use Pulse() to signal when a
next event has been Enqueue()d.

Does Wait() wait efficiently for the next pulse to arrive?
Yes.

Are pulses queued cumulatively?
No.

Or is there only one state (pulsed or not)?

Yes. The states are more like owned & unowned but the implication is (I
think) what you're looking for: Monitor::Pulse will wake a single waiting
thread a single time.
(Not insurmountable if this cannot happen.)

The docs in MSDN on Montor::Wait, Pulse, PulseAll are pretty thorough - be
sure to start by reading and understanding all of those.

-cd
 
Back
Top