Modify

#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;
}

Attachments (0)

Change History (5)

comment:1 Changed 22 months ago by Xiaoshuang LU <luxiaoshuang@…>

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 Changed 22 months ago by viboes

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

comment:3 Changed 22 months ago by viboes

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 Changed 22 months ago by viboes

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.