[threading] Fix Fence for multiple waiting threads

This commit is contained in:
Joel Linn
2020-11-06 18:45:32 +01:00
committed by Rick Gibbed
parent d7094fae52
commit 68cf47e245
2 changed files with 43 additions and 12 deletions

View File

@@ -38,6 +38,13 @@ TEST_CASE("Fence") {
pFence->Signal();
pFence->Wait();
// Signal and wait two times
pFence = std::make_unique<threading::Fence>();
pFence->Signal();
pFence->Wait();
pFence->Signal();
pFence->Wait();
// Test to synchronize multiple threads
std::atomic<int> started(0);
std::atomic<int> finished(0);
@@ -57,15 +64,10 @@ TEST_CASE("Fence") {
});
Sleep(100ms);
REQUIRE(started.load() == threads.size());
REQUIRE(finished.load() == 0);
// TODO(bwrsandman): Check if this is correct behaviour: looping with Sleep
// is the only way to get fence to signal all threads on windows
for (int i = 0; i < threads.size(); ++i) {
Sleep(10ms);
pFence->Signal();
}
REQUIRE(started.load() == threads.size());
pFence->Signal();
for (auto& t : threads) t.join();
REQUIRE(finished.load() == threads.size());