Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] await hangs when using boost::promise/future
From: Lee Clagett (forum_at_[hidden])
Date: 2015-01-17 09:36:32


On Sat, Jan 17, 2015 at 8:48 AM, TONGARI J <tongari95_at_[hidden]> wrote:

> 2015-01-17 21:45 GMT+08:00 TONGARI J <tongari95_at_[hidden]>:
>
>> Hi,
>>
>> The sample code is here:
>> https://gist.github.com/jamboree/3b8716ad1922749e77ae
>>
>> The boost::future adaption code is adapted from N4286.
>>
>> Tested with VS2015 preview.
>> If std::promise is passed, the code works fine.
>> Any clue why it hangs if boost::promise is passed?
>>
>
> Forgot to mention that it's compiled with Boost 1.57,
> BOOST_THREAD_VERSION=4, x64
>
>
>> Thanks.
>>
>
>
I found two bugs in this portion of boost::future last week, and I have
been meaning to post to trac and offer assistance in fixing. The first bug
is in the .then() continuation - it is supposed to block in this situation
(according to the docs), just like boost/std::async does if the future
object is ignored. Instead, it continues unblocked. The second bug is a
consequence of ignoring the returned future. The call to .set_value()
acquires the mutex, and invokes the continuation on a separate thread. The
continuation then tries to acquire the mutex (has_exception), and blocks
waiting for the set_value() to clear. set_value() is in turn waiting for
the continuation thread to join because nothing else has a handle to the
thread.

The best way to get around this is to _not_ ignore the returned future from
the .then call. I also have patch that fixes the second bug, but fixing the
first bug will require enough changes that will likely result in an
obsolete patch.

Lee



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net