-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_019.cpp
30 lines (26 loc) · 1004 Bytes
/
example_019.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
//SPDX-License-Identifier: Apache-2.0
//Author: Blayne Dennis
// example_019
#include <iostream>
#include "mce.hpp"
int main()
{
std::shared_ptr<mce::scheduler> cs = mce::scheduler::make();
mce::chan<int> done_ch = mce::chan<int>::make();
auto recv_function = [](mce::chan<int> done_ch)
{
int r;
done_ch.recv(r);
std::cout << "recv done" << std::endl;
mce::this_scheduler().halt();
};
auto send_function = [&](mce::chan<int> done_ch)
{
mce::this_scheduler().schedule(recv_function, done_ch);
std::cout << "send done" << std::endl;
done_ch.send(0);
};
cs->schedule(send_function, done_ch); // schedule send_function for exection
cs->run(); // execute coroutines on the current thread until halt() is called
return 0;
}