-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
48 lines (37 loc) · 1003 Bytes
/
main.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
42
43
44
45
46
47
48
#include "pooler.h"
#include <cstdio>
#include <unistd.h>
struct gooberData {
int x;
float b;
double f;
};
POOLER_FUNC(myFunc, {
gooberData* myDat = static_cast<gooberData*>(data);
for (int i=0;i<2;i++) {
printf("Hello from thread %d - x=%d, b=%f, f=%f\n", id, myDat->x, myDat->b, myDat->f);
sleep(1);
}
})
int main() {
Pooler pool(2);
gooberData inputData;
inputData.x = 3532;
inputData.b = 45.432;
inputData.f = 4384737.384723;
printf("Blocking until all threads complete their work...\n");
// inputData must not be modified after this point
pool.run(myFunc, static_cast<void*>(&inputData));
// Signal to all threads to perform a lambda function
pool.run(POOLER_LAMBDA{
for (int i=0;i<2;i++) {
printf("Hello from lambda %d\n", id);
sleep(1);
}
}); // inputData is optional (nullptr by default).
// Can also be passed as the second argument here
printf("Done!\nSending all threads a stop command...\n");
pool.stop();
printf("Done!\n");
return 0;
}