Skip to content

Instantly share code, notes, and snippets.

@nswutong
Forked from eahydra/self_coroutine.cpp
Created September 3, 2013 17:30
Show Gist options
  • Select an option

  • Save nswutong/6426955 to your computer and use it in GitHub Desktop.

Select an option

Save nswutong/6426955 to your computer and use it in GitHub Desktop.
#define begin() \
static unsigned int state_ = 0;\
switch (state_) \
case 0:
#define _yield_impl(x_, z_) \
do { \
state_ = z_; \
##x_; \
goto exit__;\
case z_:;\
} while (false)
#define _yield(y_) \
_yield_impl(y_, __COUNTER__ +1)
#define end() \
default:\
exit__:\
break
void coroutine_executor_yy() {
begin() {
_yield(task_thread_pool_.post_task([&](){
std::cout<<"yy ******yield***** 1"<<std::endl;
coroutine_executor_yy();
}));
_yield(task_thread_pool_.post_task([&](){
std::cout<<"yy ****yield**** 2"<<std::endl;
coroutine_executor_yy();
}));
end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment