Boost logo

Boost :

Subject: Re: [boost] [thread] terminating destructor
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2012-10-13 10:08:46


> std::future does
>> join without interruption. What does boost::future do? I think it should
>> interrupt and join (or perhaps detach as per N3451).
>>
>> I don't understand this. Could you clarify?
>

Sorry, I tried to say too much in one sentence. While std::thread's
destructor terminates for joinable thread, std::future's destructor sort-of
joins with the (implied) thread: it waits until the job is done. So we
already have a potentially surprising suspension upon leaving the scope. I
guess this is more acceptable for a higher level abstraction. Now, for
boost::future, I could not figure out what it does in the destructor, but
if it tries to follow std::future, it probably joins. In the case of the
future, interruption appears even more appealing because you join anyway,
and you can only speed the waiting up.

Then I referred to paper N3451 ("async and ~future"):
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3451.pdf
Herb Sutter observes that because future's destructor blocks, the following
code:

{
  async( []{ f(); } );
  async( []{ g(); } );
}

surprisingly, is executed synchronously (i.e., we do not launch the task
executing g() until the task executing f() has finished). He proposes a
change to std::future to detach in destructor. I just mention it because if
boost::future tries to follow std::future, this may become necessary one
day.

Regards,
&rzej


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk