Ticket #9151: coro_mod.cc

File coro_mod.cc, 1005 bytes (added by extproxy@…, 9 years ago)
Line 
1#include <functional>
2#include <iostream>
3#include <boost/coroutine/all.hpp>
4#include <stdlib.h>
5#include <new>
6#include <stdio.h>
7
8using namespace std;
9using namespace std::placeholders;
10using namespace boost::coroutines;
11
12void* operator new (size_t size) {
13 void *ptr = malloc(size);
14
15 printf("Allocated: %p\n", ptr);
16
17 return ptr;
18}
19
20void operator delete (void *ptr) {
21 printf("Freeing: %p\n", ptr);
22
23 free(ptr);
24}
25
26struct XX {
27
28 static void Hello(coroutine<void(int)>::caller_type& ca) {
29 cout << "In Hello " << ca.get() << endl;
30 ca();
31 cout << "In Hello end " << ca.get() << endl;
32 ca();
33 cout << "In Hello end " << ca.get() << endl;
34 }
35
36 void Run() {
37 coroutine<void(int)> coro(Hello, 6);
38
39 cout << "In Run1" << endl;
40 int x = 4;
41 while (coro) {
42 coro(x++);
43 }
44 cout << "In Run2" << endl;
45 }
46
47};
48
49int main(int argc, char **argv) {
50 printf("Starting main\n");
51
52 XX *xx = new XX;
53 xx->Run();
54 delete xx;
55
56 printf("Finished main\n");
57
58 return 0;
59}