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
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
67
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <list>
#include <string>
#include "Runtime.hpp"
#include "Common.hpp"
#include "PrivateSemaphore.hpp"
#include "BinaryPrivateSemaphore.hpp"
#include "CountingPrivateSemaphore.hpp"
#include "Debug.hpp"
#include "emper.hpp"
#include "emper-version.h"
static unsigned int ITERATIONS = 10;
static std::chrono::milliseconds SINGLE_FIBER_DURATION = std::chrono::milliseconds(3000);
static std::chrono::milliseconds MULTI_FIBER_DURATION = std::chrono::milliseconds(2000);
template<typename Rep, typename Period>
static void letsGetBusy(std::chrono::duration<Rep, Period> duration) {
const std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
const std::chrono::time_point<std::chrono::high_resolution_clock> deadline = now + duration;
while (std::chrono::high_resolution_clock::now() < deadline);
}
static void alphaFiber() {
const Runtime* runtime = Runtime::getRuntime();
const workerid_t workerCount = runtime->getWorkerCount();
std::cout << "Starting WorkerSleepExample with " << workerCount << " workers using " << ITERATIONS << " iterations." << std::endl
<< "Single fiber duration: " << SINGLE_FIBER_DURATION.count() << ", Multi fiber duration: " << MULTI_FIBER_DURATION.count() << std::endl
<< "EMPER version: " << EMPER_FULL_VERSION << std::endl;
for (unsigned int i = 0; i < ITERATIONS; ++i) {
letsGetBusy(SINGLE_FIBER_DURATION);
CPS cps;
for (workerid_t j = 0; j < workerCount; ++j) {
spawn([] {
letsGetBusy(MULTI_FIBER_DURATION);
}, cps);
}
cps.wait();
}
std::cout << "Finished WorkerSleepExample" << std::endl;
exit(EXIT_SUCCESS);
}
int main(UNUSED_ARG int argc, UNUSED_ARG char *argv[]) {
Runtime runtime;
Fiber* fibFiber = Fiber::from(&alphaFiber);
std::cout << "Just alloacted alpha fiber at " << fibFiber << std::endl;
runtime.schedule(*fibFiber);
runtime.waitUntilFinished();
return 0;
}