boost::future and continuations
I recently discovered that the Boost.Thread library implements some extensions to boost::future from the 'Technical Specification for C++ Extensions for Concurrency' [1]. The std::experimental interfaces are documented on cppreference.com [2], but neither gcc nor clang provide them.
The coolest new feature is future::then(), which takes a continuation to be called once the future is ready, and returns a future for the continuation's result. This allows futures to be composed into higher-level asynchronous operations - an ability that is sorely lacking in the c++11 std::future.
While these extensions are not enabled in boost by default, they can be turned on with a series of BOOST_THREAD_PROVIDES_FUTURE* defines (since boost 1.57). The boost documentation for 'Conformance and Extension' [3]describes the status of this implementation, listing some features as 'partial'. I wrote a set of unit tests to explore this, and was happy with the results. The only unfortunate piece missing is 'implicit unwrapping' for future::then() - if you pass it a continuation that returns a future<T>, then() will return a future<future<T>>. This -should- be implicitly converted to future<T>, but boost::future requires you to do it explicitly by calling future::unwrap().
I'm curious to see how people feel about this. Would you consider using boost::futures? Are there concerns about using boost extensions? About slight changes to interfaces? I opened a pull request [4] for discussion - take a look at the unit tests for examples, and let me know what you think.
Thanks,
Casey
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0159r0.html
[2] http://en.cppreference.com/w/cpp/experimental/concurrency
[3] http://www.boost.org/doc/libs/1_63_0/doc/html/thread/compliance.html#thread.compliance.cxx1y
[4] https://github.com/ceph/ceph/pull/14987
Quoted 21 lines · Casey Bodley
I recently discovered that the Boost.Thread library implements some extensions to
boost::futurefrom the 'Technical Specification for C++ Extensions for Concurrency' [1]. Thestd::experimentalinterfaces are documented on cppreference.com [2], but neither gcc nor clang provide them.The coolest new feature is
future::then(), which takes a continuation to be called once the future is ready, and returns a future for the continuation's result. This allows futures to be composed into higher-level asynchronous operations - an ability that is sorely lacking in the c++11std::future.While these extensions are not enabled in boost by default, they can be turned on with a series of BOOST_THREAD_PROVIDES_FUTURE* defines (since boost 1.57). The boost documentation for 'Conformance and Extension' [3]describes the status of this implementation, listing some features as 'partial'. I wrote a set of unit tests to explore this, and was happy with the results. The only unfortunate piece missing is 'implicit unwrapping' for
future::then()- if you pass it a continuation that returns a future<T>,then()will return a future<future<T>>. This -should- be implicitly converted to future<T>, butboost::futurerequires you to do it explicitly by callingfuture::unwrap().
Quoted 4 lines
I'm curious to see how people feel about this. Would you consider using
boost::futures? Are there concerns about using boost extensions? About slight changes to interfaces? I opened a pull request [4] for discussion - take a look at the unit tests for examples, and let me know what you think.
This'll probably get more attention once Luminous is out, but we need a futures library for the OSD and if there's one in Boost (that might make it into the standard?) then it'll be an obvious candidate, assuming it's capable enough to fulfill our needs!
-Greg
Quoted 27 lines · Gregory Farnum
Quoted 21 lines · Casey Bodley
I recently discovered that the Boost.Thread library implements some extensions to
boost::futurefrom the 'Technical Specification for C++ Extensions for Concurrency' [1]. Thestd::experimentalinterfaces are documented on cppreference.com [2], but neither gcc nor clang provide them.The coolest new feature is
future::then(), which takes a continuation to be called once the future is ready, and returns a future for the continuation's result. This allows futures to be composed into higher-level asynchronous operations - an ability that is sorely lacking in the c++11std::future.While these extensions are not enabled in boost by default, they can be turned on with a series of BOOST_THREAD_PROVIDES_FUTURE* defines (since boost 1.57). The boost documentation for 'Conformance and Extension' [3]describes the status of this implementation, listing some features as 'partial'. I wrote a set of unit tests to explore this, and was happy with the results. The only unfortunate piece missing is 'implicit unwrapping' for
future::then()- if you pass it a continuation that returns a future<T>,then()will return a future<future<T>>. This -should- be implicitly converted to future<T>, butboost::futurerequires you to do it explicitly by callingfuture::unwrap().Quoted 4 lines
I'm curious to see how people feel about this. Would you consider using
boost::futures? Are there concerns about using boost extensions? About slight changes to interfaces? I opened a pull request [4] for discussion - take a look at the unit tests for examples, and let me know what you think.
Quoted 4 lines
This'll probably get more attention once Luminous is out, but we need a futures library for the OSD and if there's one in Boost (that might make it into the standard?) then it'll be an obvious candidate, assuming it's capable enough to fulfill our needs!
Yeah, +100 if it's on a standards track. Is the implic unwrapping something that is planned and/or coming soon?
sage
Quoted 28 lines · Sage Weil
Quoted 27 lines · Gregory Farnum
Quoted 25 lines · Casey Bodley
I recently discovered that the Boost.Thread library implements some extensions to
boost::futurefrom the 'Technical Specification for C++ Extensions for Concurrency' [1]. Thestd::experimentalinterfaces are documented on cppreference.com [2], but neither gcc nor clang provide them.The coolest new feature is
future::then(), which takes a continuation to be called once the future is ready, and returns a future for the continuation's result. This allows futures to be composed into higher-level asynchronous operations - an ability that is sorely lacking in the c++11std::future.While these extensions are not enabled in boost by default, they can be turned on with a series of BOOST_THREAD_PROVIDES_FUTURE* defines (since boost 1.57). The boost documentation for 'Conformance and Extension' [3]describes the status of this implementation, listing some features as 'partial'. I wrote a set of unit tests to explore this, and was happy with the results. The only unfortunate piece missing is 'implicit unwrapping' for
future::then()- if you pass it a continuation that returns a future<T>,then()will return a future<future<T>>. This -should- be implicitly converted to future<T>, butboost::futurerequires you to do it explicitly by callingfuture::unwrap().I'm curious to see how people feel about this. Would you consider using
boost::futures? Are there concerns about using boost extensions? About slight changes to interfaces? I opened a pull request [4] for discussion - take a look at the unit tests for examples, and let me know what you think.
Quoted 7 lines
Quoted 4 lines
This'll probably get more attention once Luminous is out, but we need a futures library for the OSD and if there's one in Boost (that might make it into the standard?) then it'll be an obvious candidate, assuming it's capable enough to fulfill our needs!
Yeah, +100 if it's on a standards track. Is the implic unwrapping something that is planned and/or coming soon?
actually, i was wondering if i could use .then() to implement the state-driven mgr initialization logic in a more fluent way last week-end. as ceph-mgr now initialize itself with several steps, and they are scheduled in a background thread, if we have the primitive of .then() and .when_all(), i believe that would be much easier.
Quoted 6 lines
sage
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Regards Kefu Chai
Quoted 4 lines · Sage Weil
Yeah, +100 if it's on a standards track. Is the implic unwrapping something that is planned and/or coming soon?
sage
These extensions were added in boost 1.57 and haven't changed since. The related tracker issues were last modified 3 years ago:
https://svn.boost.org/trac/boost/ticket/10424
https://svn.boost.org/trac/boost/ticket/10550
Casey
Quoted 2 lines · Sage Weil
Yeah, +100 if it's on a standards track. Is the implic unwrapping something that is planned and/or coming soon?
The Concurrency TS extends std::future in several interesting directions. There's an implementation of it that's the foundation of the HPX library.
http://stellar.cct.lsu.edu/projects/hpx/
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4107.html
Hope that helps,
-Jesse