-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (36 loc) · 1.05 KB
/
main.cpp
File metadata and controls
44 lines (36 loc) · 1.05 KB
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
// Define USE_BS_THREAD_POOL to use BS::thread_pool, otherwise uses ThreadPool
// #define USE_BS_THREAD_POOL
#ifdef USE_BS_THREAD_POOL
#include "BS_thread_pool.hpp"
using Pool = BS::pause_thread_pool; // thread_pool<BS::tp::pause>
#else
#include "thread-pool.hpp"
using Pool = ThreadPool;
#endif
#include <iostream>
#include <chrono>
int main()
{
Pool pool(4);
for (int i = 0; i < 10; ++i) {
pool.submit_task([i] {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::cout << "Task " << i << " completed\n";
});
}
std::this_thread::sleep_for(std::chrono::milliseconds(250));
std::cout << "Pausing thread pool...\n";
pool.pause();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Resuming thread pool...\n";
#ifdef USE_BS_THREAD_POOL
pool.unpause();
#else
pool.resume();
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "Shutting down thread pool...\n";
#ifndef USE_BS_THREAD_POOL
pool.shutdown();
#endif
}