I have written a program using Boost threads. I have allocated two buffers (one for each of the worker threads) to store some info they are to process. They sit and wait for something to appear on the buffer, then they process it and place the results onto a different buffer. My buffer implementations are thread-safe. At present, I have the main thread busy-wait until the buffer size is zero, however this is really inefficient as it has to keep requesting control of the buffer and then checking the size. I'd like a way to sleep the main thread until BOTH worker threads signal that they are finished. I am fairly sure this can be achieved using boost::condition_variable
but I am unsure how I would do this with two worker threads.
Help greatly appreciated.
EDIT - Also, would boost::barrier
be suitable also?