Newer
Older
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
#include "emper.hpp"
#include <atomic>
#include "CountingPrivateSemaphore.hpp"
static std::atomic_uint counter;
static void increaseCounterByOne() {
counter++;
}
static void mainFiber(void) {
const unsigned int FIBER_COUNT = 100;
CountingPrivateSemaphore cps;
for (unsigned int i = 0; i < FIBER_COUNT; ++i) {
spawn(&increaseCounterByOne, cps);
}
cps.wait();
if (counter != FIBER_COUNT) {
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
int main(UNUSED_ARG int arg, UNUSED_ARG char *argv[]) {
Runtime runtime;
async(&mainFiber);
runtime.waitUntilFinished();
return EXIT_FAILURE;
}