Skip to content

Commit ec6b79a

Browse files
updated threadpool
1 parent 5ca980b commit ec6b79a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

example/threadpool.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ auto linear_insertions() {
2424
std::atomic<size_t> sum {0};
2525

2626
std::function<void(int)> insert;
27-
std::promise<void> promise;
27+
std::promise<int> promise;
2828
auto future = promise.get_future();
2929

3030
insert = [&threadpool, &insert, &sum, &promise] (int i) {
@@ -35,7 +35,7 @@ auto linear_insertions() {
3535
}
3636
else {
3737
if(auto s = ++sum; s == threadpool.num_workers()) {
38-
promise.set_value();
38+
promise.set_value(1);
3939
}
4040
}
4141
};
@@ -45,7 +45,10 @@ auto linear_insertions() {
4545
}
4646

4747
// synchronize until all tasks finish
48-
future.get();
48+
threadpool.wait_for_all();
49+
50+
assert(future.wait_for(std::chrono::seconds(0)) == std::future_status::ready);
51+
assert(future.get() == 1);
4952
assert(sum == num_threads);
5053

5154
auto end = std::chrono::high_resolution_clock::now();

0 commit comments

Comments
 (0)