-
Notifications
You must be signed in to change notification settings - Fork 0
/
tptest.cc
32 lines (28 loc) · 783 Bytes
/
tptest.cc
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
/**
* File: tptest.cc
* ---------------
* Simple test in place to verify that the ThreadPool class works.
*/
#include <iostream>
#include "thread-pool.h"
#include "thread-utils.h"
#include "ostreamlock.h"
using namespace std;
static const size_t kNumThreads = 12;
static const size_t kNumFunctions = 1000;
static void simpleTest() {
ThreadPool pool(kNumThreads);
for (size_t id = 0; id < kNumFunctions; id++) {
pool.schedule([id] {
cout << oslock << "Thread (ID: " << id << ") has started." << endl << osunlock;
size_t sleepTime = (id % 3) * 10;
sleep_for(sleepTime);
cout << oslock << "Thread (ID: " << id << ") has finished." << endl << osunlock;
});
}
pool.wait();
}
int main(int argc, char *argv[]) {
simpleTest();
return 0;
}