Boost logo

Boost :

Subject: Re: [boost] [thread] countdown_latch
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-04-21 18:55:16

On 4/21/2013 4:53 PM, Vicente J. Botet Escriba wrote:
> You are surely right. My first approach would be option 3, but it has a
> lot of troubles as you note.
> I suspect that the completion_latch needs a latch internally to ensure
> that all the waiters have been finished.
> The best would be to prototype these ideas and see what can be done.

Back to the original example with widget for a second whether it is a
latch or a barrier it is only used on construction but then kept around
as member for the entire lifetime of the object.

This seems unnecessary but also seems to be the pattern I've seen

Would it be better to do something like:

class widget
         countdown_latch latch(1);
         thread_ = std::thread( [&]{ thread_func( latch ); }

     void setup();
     void run();

     void thread_func( countdown_latch& latch )
         // from here on latch is a dangling reference don't use


     std::thread thread_;

Or is there something cleaner?

Boost list run by bdawes at, gregod at, cpdaniel at, john at