
Asheh wrote:
Hi, Having trouble with sleeping N threads while I need to wake them. Since boost contains no sleep/wake functionality I have tried using boost::condition, I have had trouble with this too (it seems to cause locks). Somone mentioned boost::barrier I read about it in the documentation and it appears to function in a way I would require, here is what im looking for:
I reach a point in the program where I segment a pieces of data and it needs to be processed in parallel on two threads, the main thread waits for the two worker threads to finish processing then continues on, those two threads (or N threads..) must then go back to sleep until they are needed again.
Can anyone provide a good solution, if boost::barrier is what im looking for could you help me describe how Id correctly impliment this?
Create a barrier with a count of 3 before spawning the 2 worker threads. Controlling thread waits on the barrier after spawning the worker threads and worker threads wait on the same barrier at the end of their work. None of the three threads will pass the barrier until all are waiting on it, at which point they all proceed. Another name for a barrier is a rendezvous which is more descriptive in my opinion.
Thanks Ashley.
HTH Bill Somerville