-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (43 loc) · 1.15 KB
/
main.cpp
File metadata and controls
66 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include "Coroutine.h"
#include "CoChannel.h"
using namespace std;
void consumer(void* n)
{
CoChannel* chan = (CoChannel*)n;
cout<<"consumer begin............."<<endl;
while(chan->recv())
{
int a =(int)chan->get_data();
cout<<"rev:"<<a<<endl;
}
cout<<"consumer end............."<<endl;
}
void producer(void* n)
{
CoChannel* chan = (CoChannel*)n;
cout<<"producer begin............."<<endl;
for (int i = 0; i < 20; ++i)
{
cout<<"send i :"<< i <<endl;
chan->send((void*)i);
}
chan->close();
cout<<"producer end............."<<endl;
}
//make the compiler happy....
void run(void*)
{
cout<<"in run"<<endl;
//******the channel will be released automatically by the receiver
CoChannel* ch = CoChannel::create();
//******the channel will be released automatically by the receiver
Coroutine::go(consumer,(void*)ch,"co1");
Coroutine::go(producer,(void*)ch,"co2");
cout<<"run finished"<<endl;
}
int main(){
cout<<"Hello world!"<<endl;
Coroutine::launch_scheduler(run, (void*)NULL);
return 0;
}