-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathago_test.cpp
More file actions
41 lines (31 loc) · 746 Bytes
/
ago_test.cpp
File metadata and controls
41 lines (31 loc) · 746 Bytes
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
/* COMPILE: "cmake ." to generate Makefile, "make" to build ago library and ago_test test program.
*/
/* a test of the lightweight thread implementation in ago */
/** Quick documentation:
* Create ago object before doing anything,
* ago::go() to start a lightweight thread,
* and destruct ago object when you're finished.
*/
#include <iostream>
#include <mutex>
#include <functional>
#include "ago.h"
static std::mutex m;
static void worker(int *a)
{
std::lock_guard<std::mutex> lock(m);
std::cout << "Worker #" << *a << std::endl;
}
int main()
{
ago r(4);
int a[2048];
for(int i = 0; i < 2048; ++i)
{
a[i] = i + 1;
r.go(std::bind(&worker, a + i));
}
r.wait();
std::cout << "after wait." << std::endl;
return 0;
}