On 13/05/2013 02.46, Rob Stewart wrote:
On May 12, 2013, at 6:45 PM, Michael Marcin
wrote: On 5/12/2013 6:49 AM, Rob Stewart wrote:
On May 11, 2013, at 5:29 PM, Gaetano Mendola
wrote: On 21/04/2013 12.54, Rob Stewart wrote:
I'd prefer to create a barrier class and, in your example, it would release waiting threads when two are blocked behind it. IOW, you'd create a barrier for two threads and both thread_proc() and the constructor would wait() on the barrier. Once both threads have called wait(), they are both released. (I plan to present that at C++ Now, this year.)
As said that's create a not needed "wait" on the thread body, what the OP (and me for the matter) needs is that *only* thread creator is blocked waiting for the threads to arrive at certain point of the execution.
It seems to me that wait is inconsequential relative to the cost of creating a thread. If this were part of the thread creation process, an option to thread's constructor, say, there would be some convenience, but the performance difference doesn't seem worthwhile. Have I missed something?
The created thread is already executing when it gets to the latch. Why would you want to introduce synchronization, and potentially block the thread, where none is needed?
Is the latch to just cause the creator to block until the created thread begins, or is it more general purpose to cause a number of threads to wait until they are all ready? I thought it was the latter and, if so, how can it be done without synchronization? I must still be missing something.
The latch is to just cause the creator to block until the created thread begins. At the moment with boost off-the-shelf you can achieve it using a barrier but doing so you are blocking the thread as well, what me and the OP needs is that the thread creator will eventualy block waiting for the thread not the other way around. You can achieve it using a syncronization mechanims named "latch": boost::latch myLatch(1); myLatch.count_down(); /// This is not a blocking operation myLatch.wait(); /// This is blocking if a count_down() was not issued of course latch is implemented with condition. Regards Gateno Mendiola