#include #include #include #include #include #include using namespace std; using namespace std::placeholders; using namespace boost::coroutines; void* operator new (size_t size) { void *ptr = malloc(size); printf("Allocated: %p\n", ptr); return ptr; } void operator delete (void *ptr) { printf("Freeing: %p\n", ptr); free(ptr); } struct XX { static void Hello(coroutine::caller_type& ca) { cout << "In Hello " << ca.get() << endl; ca(); cout << "In Hello end " << ca.get() << endl; ca(); cout << "In Hello end " << ca.get() << endl; } void Run() { coroutine coro(Hello, 6); cout << "In Run1" << endl; int x = 4; while (coro) { coro(x++); } cout << "In Run2" << endl; } }; int main(int argc, char **argv) { printf("Starting main\n"); XX *xx = new XX; xx->Run(); delete xx; printf("Finished main\n"); return 0; }