Fixing up threadpool
This commit is contained in:
@@ -12,13 +12,20 @@ TEST_CASE("Threadpool Construction", "[threadpool]") {
|
||||
ThreadPool tp(10);
|
||||
|
||||
std::vector<std::future<void>> res;
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
res.push_back(tp.addTask([&cnt]() -> void { cnt++; return; }));
|
||||
|
||||
SECTION("Simple runs") {
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
res.push_back(tp.addTask([&cnt]() { cnt++; return; }));
|
||||
for (auto & r : res) r.get();
|
||||
REQUIRE(cnt == 100);
|
||||
}
|
||||
|
||||
for (auto & r : res) {
|
||||
r.get();
|
||||
SECTION("Slow runs") {
|
||||
using namespace std::chrono_literals;
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
res.push_back(tp.addTask([&cnt]() { std::this_thread::sleep_for(20ms); cnt++; return; }));
|
||||
for (auto & r : res) r.get();
|
||||
REQUIRE(cnt == 100);
|
||||
}
|
||||
|
||||
REQUIRE(cnt == 100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user