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.
2015-09-17 13:35 GMT+02:00 Mikhail Strelnikov
I have an issue after switching from Boost.Coroutine to Boost.Coroutine2 - nested coroutine switches to its creator - not to the caller.
this is not how asymmetric coroutines are defined - a asymmetric coroutine has to return to its resumption point while suspended
Here is the code - http://codepad.org/WGNs0N7F
your code line 25 looks strange coroutine::pull_type default_coroutine = coroutine::pull_type(std::move( default_coroutine)); Is it a bug of Boost.Coroutine2? If not, how can I change this code to work
equally for Boost.Coroutine and Boost.Coroutine2?
instead of using coroutines I suggest to use class execution_context from boost.context (fucntions like symmetric coroutines)
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.
the constructor requires a function which will be executed in side the coroutine
Oliver, thank you for your answer, it is very helpful.
I have an issue after switching from Boost.Coroutine to Boost.Coroutine2 - nested coroutine switches to its creator - not to the caller.
this is not how asymmetric coroutines are defined - a asymmetric coroutine has to return to its resumption point while suspended
Okay. But where "resumption point" belongs to? To the caller or to the creator? Sorry for posting such a long code, I think now I've simplified it - http://codepad.org/yRqRfQBI Output: When using Boost.Coroutine result is 122 When using Boost.Coroutine2 result is 1221 So there is one template test<> instantiated twice (with coroutines::coroutine<void> and coroutines2::coroutine<void>) results in two different outputs "122" and "1221". This "122" makes perfect sense. Why calling 2nd coroutine leads to calling 1st in case of Boost.Coroutine2? What is motivation for this? Now if you'll comment line 30 containing "yield();" it will still work for Boost.Coroutine but crash on assert for Boost.Coroutine2. This means inner coroutine shoud have less steps than outer coroutine. What is motivation behind that?
2015-09-18 6:26 GMT+02:00 Mikhail Strelnikov
Now if you'll comment line 30 containing "yield();" it will still work for Boost.Coroutine but crash on assert for Boost.Coroutine2. This means inner coroutine shoud have less steps than outer coroutine. What is motivation behind that?
Without 'yield()' in line 30 the parent coroutine terminates/is complete (e.g. it leaves your lambda after line 31). Leaving the lambda of the parent coroutine issues a jump back so you return from 'start_parent_coroutine()'. Line 39 calls the child coroutine. 'yield();' at line 16 (inside the child coroutine) triggers a context switch to the parent coroutine which is already complete. That is because the child coroutine is created inside the parent coroutine and thus the calling context is the stack of the parent coroutine.
thy, you figured out a bug - a function call was missing (a bug fix will follow this evening).
I'm sorry for being so annoying, but by "missing" you mean you'll fix Boost.Coroutine and will leave Boost.Coroutine2 as it is now? I do understand that Lua is not a reference language, but its behaviour matches Boost.Coroutine's behaviour - https://ideone.com/3RWPKF and prints 122. Again, I'm not saying this - http://www.inf.puc-rio.br/~roberto/docs/MCC15-04.pdf should be trusted but it says that: "Lua coroutine facilities implement our concept of full asymmetric coroutines [Moura et al. 2004]" May be you can add a parameter for user to choose which behaviour they want? Thanks.
2015-09-18 15:45 GMT+02:00 Mikhail Strelnikov
thy, you figured out a bug - a function call was missing (a bug fix will follow this evening).
I'm sorry for being so annoying, but by "missing" you mean you'll fix Boost.Coroutine and will leave Boost.Coroutine2 as it is now?
coroutine2
I do understand that Lua is not a reference language, but its behaviour matches Boost.Coroutine's behaviour - https://ideone.com/3RWPKF and prints 122.
boost.coroutine2 is fixed now
participants (2)
-
Mikhail Strelnikov
-
Oliver Kowalke