Boost logo

Boost :

Subject: [boost] [thread] How to return a lazy future ?
From: Ivan Le Lann (ivan.lelann_at_[hidden])
Date: 2011-10-12 12:35:48


Boost.Thread documentation has a section regarding the creation of lazy futures.

The code on this page runs fine, but I can't find a way to return such future.
Naïve code below exits with a boost::broken_promise in unique_future::get().

boost::unique_future <int> create_future()
    boost::packaged_task<int> task(calculate_the_answer_to_life_the_universe_and_everything);
    return task.get_future();

int main()

Exceptional finish is marked in packaged_task destructor.
And regardless of exceptions, since set_wait_callback want something
that operates on packaged_task and not on pointed task_base,
the code is doomed to do an access violation.

So, is there any way to return lazy futures ?


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