[LC++] Waking multiple threads

Julien Claassen julien at c-lab.de
Sun Sep 6 04:11:27 EST 2009


Hello everyone!
   Could you please consider the following problem and try to point me in the 
right direction. One note in advance: For those of you, who know it, I'm using 
the boost libraries version 1.4.0.

1. I have a user-input-thread
2. I have multiple output-threads (the program's engine and the screen-output 
at least).
3. I get input from my input-thread and want to wake all output-threads to 
take it in and process it.

   My ideas on the subject:
Use a condition variable to put all the output-threads in waiting mode.
   Use a signal in the input thread, when something comes.
   The slots in the output-threads contain a wakeup call.
   So the signal calls each slot sequentially and all the output threads get 
their data.

   I'm doubting myself here. I wondered, if I better should use a condition 
variable for each output-thread, store them in some container and ask the 
input-thread on incoming data, to iterate through the container and send a 
notify call on each condition variable.
   At least one flaw I see with the first "solution?" is, that boost doesn't 
offer a directed wakeup-call. I can't say: notify this specific thread.
   Or can a condition variable be associated with different mutexes. That would 
indeed solve the problem. A simple notify_all would do it.
   I'd be grateful for any help!
   Friendly regards
          Julien

--------
Music was my first love and it will be my last (John Miles)

======== FIND MY WEB-PROJECT AT: ========
http://ltsb.sourceforge.net
the Linux TextBased Studio guide
======= AND MY PERSONAL PAGES AT: =======
http://www.juliencoder.de



More information about the tuxCPProgramming mailing list