[coroutine] Launch a thread in a coroutine

Hi, Is it possible to launch a thread in a coroutine? Such that this code would work: #include <iostream> #include <thread> #include <boost/coroutine/all.hpp> std::thread t; void push_data2(boost::coroutines::coroutine<std::string>::push_type sink) { sink("test2"); } void push_data(boost::coroutines::coroutine<std::string>::push_type& sink) { sink("test1"); t = std::thread(push_data2, std::move(sink)); } int main() { boost::coroutines::coroutine<std::string>::pull_type source(push_data); auto b = boost::begin(source); auto e = boost::end(source); std::cout << *b << std::endl; ++b; std::cout << *b << std::endl; t.join() return 0; } Output: test1 parser: /usr/local/include/boost/smart_ptr/intrusive_ptr.hpp:162: T* boost::intrusive_ptr<T>::operator->() const [with T = boost::coroutines::detail::push_coroutine_base<std::basic_string<char>
]: Assertion `px != 0' failed. Aborted (core dumped)

2014/1/15 Pierre Talbot <ptalbot@hyc.io>
void push_data(boost::coroutines::coroutine<std::string>::push_type& sink) { sink("test1"); t = std::thread(push_data2, std::move(sink)); }
'sink' is synthesized by the framework and is attached to coroutine-stack. because you move the synth. coroutine, the code inside the framework can't access it any more (therefore the assertion from intrusive_ptr<>).

On 01/16/2014 03:36 PM, Oliver Kowalke wrote:
2014/1/15 Pierre Talbot <ptalbot@hyc.io <mailto:ptalbot@hyc.io>>
void push_data(boost::coroutines::coroutine<std::string>::push_type& sink) { sink("test1"); t = std::thread(push_data2, std::move(sink)); }
'sink' is synthesized by the framework and is attached to coroutine-stack. because you move the synth. coroutine, the code inside the framework can't access it any more (therefore the assertion from intrusive_ptr<>).
Thanks, is there something planned in the future for such a capability, as a function "move_to_thread"? Or is there a way that already exists to do that?

2014/1/18 Pierre Talbot <ptalbot@hyc.io>
Thanks, is there something planned in the future for such a capability, as a function "move_to_thread"? Or is there a way that already exists to do that?
coroutines can work only in one thread - you can't have a coroutine in thread A and its counterpart, synthesized by the framework (used to switch back to calling context), move to another thread B

On 01/18/2014 08:59 AM, Oliver Kowalke wrote:
2014/1/18 Pierre Talbot <ptalbot@hyc.io <mailto:ptalbot@hyc.io>>
Thanks, is there something planned in the future for such a capability, as a function "move_to_thread"? Or is there a way that already exists to do that?
coroutines can work only in one thread - you can't have a coroutine in thread A and its counterpart, synthesized by the framework (used to switch back to calling context), move to another thread B
That makes senses, thanks for responses.
participants (2)
-
Oliver Kowalke
-
Pierre Talbot