-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomtayexample.cpp
57 lines (42 loc) · 1.18 KB
/
comtayexample.cpp
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
/******************************************************************************
This is an example using COMTAY coroutine manager.
Download COMTAY at https://opensimply.org/comtay/
******************************************************************************/
#include <iostream>
#include <string>
#include "comtay.hpp"
using namespace comtay;
using namespace std;
class CoTask1 : public CoTask {
protected:
void body() override;
};
class CoTask2 : public CoTask {
protected:
void body() override;
};
CoTask1* pCoTask1 = nullptr;
CoTask2* pCoTask2 = nullptr;
int main() {
initializeComtay();
pCoTask1 = new CoTask1{};
pCoTask2 = new CoTask2{};
pCoTask1->start();
delete pCoTask1;
delete pCoTask2;
cout << "\nPress ENTER for program termination" << endl;
cin.get();
return 0;
}
void CoTask1::body() { // Description of Task #1
for (int i = 0; i < 3; i++) {
cout << "Hello, ";
resume(pCoTask2);
}
};
void CoTask2::body() { // Description of Task #2
for (;;) {
cout << "World!" << endl;
suspend();
};
}