-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_advanced.cpp
More file actions
37 lines (29 loc) · 889 Bytes
/
Copy pathexample_advanced.cpp
File metadata and controls
37 lines (29 loc) · 889 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
// Example: Configure BThreadPool parameters and mix fast/slow queue submissions.
// Use this pattern when you need explicit control over sizing and scheduling behavior.
#include <bthpool/bthpool.hpp>
#include <future>
#include <iostream>
#include <vector>
int main() {
bthpool::BThreadPoolParam param;
param.core_thread_num = 2;
param.max_thread_num = 6;
param.fast_queue_capacity = 64;
param.thread_clean_interval = 200;
bthpool::BThreadPool<> pool(param);
for (int i = 0; i < 8; ++i) {
pool.post([i] { (void)i; });
}
pool.defer([] { /* lower-priority work */ });
std::vector<std::future<int>> futures;
for (int i = 0; i < 4; ++i) {
futures.push_back(pool.futured_post([i] { return i * i; }));
}
pool.join();
int sum = 0;
for (auto& f : futures) {
sum += f.get();
}
std::cout << "sum of squares: " << sum << std::endl;
return 0;
}