Boost logo

Boost :

Subject: [boost] [Coroutine] Back to the caller
From: Mikhail Strelnikov (mikhail.strelnikov_at_[hidden])
Date: 2015-09-17 07:35:31


Hi,

I have an issue after switching from Boost.Coroutine to Boost.Coroutine2 -
nested coroutine switches to its creator - not to the caller.

Here is the code - http://codepad.org/WGNs0N7F

There are two coroutines (1st coroutine starts, makes some progress, then
spawns 2nd coroutine. But 1st coroutine knows nothing about 2nd and does
not communicate with it - main thread does).

With Boost.Coroutine it works as expected and outputs:

    g1g1g1g1g2g1g2g1g2g1g2g1g2g1g2g1 leaving coroutine 1
    g2g2g2g2 leaving coroutine 2

Here you can see that 1st coroutine exits but 2nd keeps working normally.
And control from coroutines is returned back to the caller (g - caller, 1
and 2 - coroutines).

But with Boost.Coroutine2 it outputs:

    g1g1g1g1g21g1g21g1g1g21 leaving coroutine 1
    assertion failed : (false) && ("pull_coroutine is complete")

Here you can see that when caller (g) calls 2nd coroutine, it does not
yield back to caller, but instead switches to 1st coroutine ("g21" in
output).Then it terminates on assert "pull_coroutine is complete".

Is it a bug of Boost.Coroutine2? If not, how can I change this code to work
equally for Boost.Coroutine and Boost.Coroutine2?

Thanks!

P.S. What is the reason of boost::coroutines2::coroutine<void>::pull_type
not having default constructor? It is still possible to have an "empty"
pull_type, but it is painful process.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk