[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.programming.threads

How to block on multiple msg queues??

worzella

7/23/2004 7:43:00 PM

In a POSIX/Linux environment, I want to be able to have a thread block
on two msg queues simultaneously, and unblock if a msg arrives on
EITHER of the queues.

I wonder if there is an existing means of doing this without me
writing some flaky polling code.

My best parallel to this is a SELECT, which allows a thread to block
on multiple sockets at the same time.

Thanks,

Randy Worzella
1 Answer

David Schwartz

7/23/2004 10:10:00 PM

0


"Randy Worzella" <worzella@us.ibm.com> wrote in message
news:b066efb.0407231143.56bebbd7@posting.google.com...

> In a POSIX/Linux environment, I want to be able to have a thread block
> on two msg queues simultaneously, and unblock if a msg arrives on
> EITHER of the queues.
>
> I wonder if there is an existing means of doing this without me
> writing some flaky polling code.

There are two good ways. One is to have whatever thread puts a message
on the queue also signal a condition variable associated with a mutex. Any
message queues that might share an interested thread also share a condition
variable. Another way is to use helper threads that block on the message
queue and set a condition and signal a condition variable. It depends upon
which threads you have control over. If you only have control over the
thread doing the waiting, then have it use one or more helper threads.

> My best parallel to this is a SELECT, which allows a thread to block
> on multiple sockets at the same time.

Well, right, but that's because you have no control over how the kernel
marks sockets ready. You are presumed to have control over all the threads
in your process because they must fully cooperate.

DS