Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2008-05-11 05:53:58

Hi all,

I have updated my prototype futures library implementation in light of various
comments received, and my own thoughts.

The new version is available for download, again under the Boost Software
License. It still needs to be compiled against the Boost Subversion Trunk, as
it uses the Boost Exception library, which is not available in an official
boost release.

Sample usage can be seen in the test harness. The support for alternative
allocators is still missing.


* I have removed the try_get/timed_get functions, as they can be replaced with
  a combination of wait() or timed_wait() and get(), and they don't work with
  unique_future<R&> or unique_future<void>.

* I've also removed the move() functions on unique_future. Instead, get()
  returns an rvalue-reference to allow moving in those types with move
  support. Yes, if you call get() twice on a movable type then the second
  get() returns an empty shell of an object, but I don't really think that's a
  problem: if you want to call get() multiple times, use a shared_future. I've
  implemented this with both rvalue-references and the boost.thread move
  emulation, so you can have a unique_future<boost::thread> if
  necessary. test_unique_future_for_move_only_udt() in test_futures.cpp shows
  this in action with a user-defined movable-only type X.

* Finally, I've added a set_wait_callback() function to both promise and
  packaged_task. This allows for lazy-futures which don't actually run the
  operation to generate the value until the value is needed: no threading
  required. It also allows for a thread pool to do task stealing if a pool
  thread waits for a task that's not started yet. The callbacks must be
  thread-safe as they are potentially called from many waiting threads
  simultaneously. At the moment, I've specified the callbacks as taking a
  non-const reference to the promise or packaged_task for which they are set,
  but I'm open to just making them be any callable function, and leaving it up
  to the user to call bind() to do that.

I've left the wait operations as wait() and timed_wait(), but I've had a
suggestion to use wait()/wait_for()/wait_until(), which I'm actively

Please download it, try it out, and let me know what you think.


Anthony Williams            | Just Software Solutions Ltd
Custom Software Development |
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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