Fixing up threadpool

This commit is contained in:
Ian Roddis
2021-06-20 10:33:35 -03:00
parent 1003e88303
commit 209ec6f380
4 changed files with 32 additions and 14 deletions

View File

@@ -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);
}