Opened 7 years ago

Closed 7 years ago

#11818 closed Bugs (fixed)

future.then will be blocked if promise is set after the invocation of then

Reported by: Xiaoshuang LU <luxiaoshuang@…> Owned by: viboes
Milestone: Boost 1.60.0 Component: thread
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description (last modified by viboes)

int function()
{
    boost::promise<int> promise;
    boost::future<int> future = promise.get_future();

    boost::future<int> result =
    future.then
    (
        boost::launch::deferred,
        [](boost::future<int> && f)
        {
            std::cout << std::this_thread::get_id() << ": callback" << std::endl;
            std::cout << "The value is: " << f.get() << std::endl;
            return f.get();
        }
    );

    // We could not reach here.
    std::cout << std::this_thread::get_id() << ": function" << std::endl;

    promise.set_value(0);

    return 0;
}

Change History (5)

comment:1 by Xiaoshuang LU <luxiaoshuang@…>, 7 years ago

Summary: future.then will be blocked if promise is set after then invocation of thenfuture.then will be blocked if promise is set after the invocation of then

comment:2 by viboes, 7 years ago

Description: modified (diff)
Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:3 by viboes, 7 years ago

I believe this is a bug.

When you launch the continuation with deferred policy, the continuation shouldn't be executed until a call to result.get() is done.

Actually the future.then(launch::deferred, f) do a call to future.wait() and so it blocks.

I will try to fix it for the next release, but the release is upcoming :(

comment:5 by viboes, 7 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.