For coroutine, we need to schedule the thread manually.
There are benefits for coroutine over the thread. The os dont have to be busy switching the thread (we do it manually).
Check the following code
#include <boost/coroutine/all.hpp>
#include <iostream>
using namespace boost::coroutines;
void cooperative(coroutine<void>::push_type &sink)
{
std::cout << "Hello";
sink();
std::cout << "world";
}
int main()
{
coroutine<void>::pull_type source{cooperative};
std::cout << ", ";
source();
std::cout << "!\n";
}
How to compile:
g++ -g coroutine.cpp -o coroutine -lboost_system -lboost_coroutine -std=c++11
Reference:
http://jolestar.com/parallel-programming-model-thread-goroutine-actor/
https://theboostcpplibraries.com/boost.coroutine
http://blog.csdn.net/hairetz/article/details/16119911