Skip to contentSkip to conversation

boost::future and continuations

DISCUSSION Casey Bodley 5 participants 6 messages May 9, 2017 – May 10, 2017

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 21 lines · Casey Bodley

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().

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

#2 lore raw
Quoted 27 lines · Gregory Farnum
Quoted 21 lines · Casey Bodley

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().

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

#3 lore raw
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::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.

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