forked from jegonzal/PowerGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fiber_test.cpp
41 lines (36 loc) · 960 Bytes
/
fiber_test.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
#include <iostream>
#include <graphlab/parallel/fiber_group.hpp>
#include <graphlab/util/timer.hpp>
using namespace graphlab;
int numticks = 0;
void threadfn() {
timer ti; ti.start();
while(1) {
if (ti.current_time() >= 1) break;
fiber_control::yield();
__sync_fetch_and_add(&numticks, 1);
}
}
void threadfn2() {
timer ti; ti.start();
while(1) {
if (ti.current_time() >= 2) break;
fiber_control::yield();
__sync_fetch_and_add(&numticks, 2);
}
}
int main(int argc, char** argv) {
timer ti; ti.start();
fiber_group group;
fiber_group group2;
for (int i = 0;i < 100000; ++i) {
group.launch(threadfn);
group2.launch(threadfn2);
}
group.join();
std::cout << "Completion in " << ti.current_time() << "s\n";
std::cout << "Context Switches: " << numticks << "\n";
group2.join();
std::cout << "Completion in " << ti.current_time() << "s\n";
std::cout << "Context Switches: " << numticks << "\n";
}