Boost logo

Boost Users :

Subject: [Boost-users] [coroutine] Launch a thread in a coroutine
From: Pierre Talbot (ptalbot_at_[hidden])
Date: 2014-01-15 04:28:55


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)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net