Fixing race condition issue with references in forking executor

This commit is contained in:
Ian Roddis
2021-09-15 14:12:55 -03:00
parent a6a7501d12
commit d4ec744773
6 changed files with 35 additions and 48 deletions

View File

@@ -38,25 +38,4 @@ TEST_CASE("threadpool", "[threadpool]") {
for (auto &r: res) r.get();
REQUIRE(cnt == 100);
}
SECTION("parallel") {
std::vector<std::future<void>> res;
using namespace std::chrono_literals;
std::atomic<uint32_t> maxCnt{0};
for (size_t i = 0; i < 100; ++i)
res.push_back(tp.addTask([&cnt,&maxCnt, i]() {
auto delay = 20ms;
uint32_t current = cnt.fetch_add(1);
delay += i * 1ms;
std::this_thread::sleep_for(delay);
if (current > maxCnt) {
maxCnt = current;
}
cnt--;
return;
}));
for (auto &r: res) r.get();
REQUIRE(maxCnt > 1);
}
}