Does boost promise/future support corroutines?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Does boost promise/future support corroutines?

Boost - Users mailing list
Hi,

Does boost promise/future support coroutines?

For example, the get call only block the running coroutine, instead of the whole thread?

Thanks,
David


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Does boost promise/future support corroutines?

Boost - Users mailing list
On 17/10/2020 05:45, David Frank wrote:
> Does boost promise/future support coroutines?
>
> For example, the get call only block the running coroutine, instead of
> the whole thread?

That depends which ones you mean (on both ends).

The promise/future from Boost.Thread will block the whole thread, naturally.

The promise/future from Boost.Fiber will block the whole fiber (which is
a type of coroutine, but is different from C++20 coroutines).

Futures and coroutines aren't really a great fit together, since the
former only has a blocking interface while the latter is intended to be
used in an entirely non-blocking fashion.

If you're wanting to work with C++20 style coroutines, probably your
best bet is to use a library such as CppCoro.  While this doesn't have a
"future" class per se, it does have the equivalent async version as
"task", and it's possible to do sync waits or wrap it in a future if you
do want to block a thread for some reason.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Does boost promise/future support corroutines?

Boost - Users mailing list
On 18/10/2020 22:55, Gavin Lambert via Boost-users wrote:
> On 17/10/2020 05:45, David Frank wrote:
>> Does boost promise/future support coroutines?
>>
> Futures and coroutines aren't really a great fit together, since the
> former only has a blocking interface while the latter is intended to be
> used in an entirely non-blocking fashion.

The OP probably was asking if Boost's futures have the coroutines markup
to make them into C++ Coroutine awaitables, like std::future is in MSVC
only.

From a quick search of
https://www.boost.org/doc/libs/1_74_0/boost/thread/future.hpp, the
answer is no. HOWEVER Boost.Thread's futures do implement .then(), and
via that the additional coroutine markup needed is trivially easy.

(In fact, someone ought to implement that markup if __cpp_coroutines
defined and submit it as a PR, because it's certainly very convenient,
albeit quite inefficient)

> If you're wanting to work with C++20 style coroutines, probably your
> best bet is to use a library such as CppCoro.  While this doesn't have a
> "future" class per se, it does have the equivalent async version as
> "task", and it's possible to do sync waits or wrap it in a future if you
> do want to block a thread for some reason.

We've moved on from task<T> :)

We now have (probably) eager<T> and lazy<T>. Boost.Outcome has
implementations which work just fine with T's having nothing to do with
Outcome.

If the OP wants to resume coroutines on different kernel threads to
where they were suspended, then they'll need to use atomic_eager<T> and
atomic_lazy<T> instead.

https://www.boost.org/doc/libs/develop/libs/outcome/doc/html/reference/types/awaitables/eager.html

https://www.boost.org/doc/libs/develop/libs/outcome/doc/html/reference/types/awaitables/lazy.html

Niall
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Does boost promise/future support corroutines?

Boost - Users mailing list
On 19/10/2020 23:53, Niall Douglas wrote:
> We've moved on from task<T> :)
>
> We now have (probably) eager<T> and lazy<T>.

That's good.  I've long regarded laziness as the biggest misfeature of
both future<T> and task<T>.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users