Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] boost futures vs C++0x futures
From: Anthony Williams (anthony_at_[hidden])
Date: 2010-03-03 17:44:51


On 03/03/10 20:54, Conoscenza Silente wrote:
> Hi All
> Only today In the Thread library I noticed in the synchronization
> section the classes boost::unique_future, boost::shared_future and boost::promise.
> Are these classes the same "futures and promises" of the the next
> C++0x classes or it is missing something in the current boost
> implementation?
> I would like to start getting confident with these new tools, but I
> would like also to know what are the difference with the ones that will
> come out in the C++0x.

These are similar to but not the same as the C++0x futures. They were
based on an early draft of the futures paper, and futures have been
changed several times since then. The current differences are:

* unique_future is now just std::future.
* There is a new std::atomic_future.
* The get_state, is_ready, has_value and has_exception members have gone.
* The timed_wait functions are called wait_for and wait_until.
* future::get moves the value out of the future, so the future is no
longer valid (testable with the new valid() member function) after a
call to get(). shared_future and atomic_future still remain valid after
a call to get(), and just return a const reference to the value.
* std::promise lacks the set_wait_callback function, but is otherwise
essentially the same.
* Errors are reported with a std::future_error exception with an error
code rather than separate exception types.
* std::packaged_task takes a function signature like std::function as
the template parameter, whereas boost::packaged_task takes the return
type only. The argument list of the function signature is used as the
argument list of the function call operator.
* std::packaged_task is lacking the set_wait_callback function
* The boost implementation is lacking std::async

Anthony

-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++0x thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk