[threading] Add complex wait on multiple test

This commit is contained in:
Sandy Carter 2019-01-16 18:23:52 -08:00 committed by Rick Gibbed
parent e9e269622b
commit cb905fb195
1 changed files with 24 additions and 2 deletions

View File

@ -200,8 +200,30 @@ TEST_CASE("HighResolutionTimer") {
} }
TEST_CASE("Wait on Multiple Handles", "Wait") { TEST_CASE("Wait on Multiple Handles", "Wait") {
// TODO(bwrsandman): auto mutant = Mutant::Create(true);
REQUIRE(true); auto semaphore = Semaphore::Create(10, 10);
auto event_ = Event::CreateManualResetEvent(false);
auto thread = Thread::Create({}, [&mutant, &semaphore, &event_] {
event_->Set();
Wait(mutant.get(), false, 25ms);
semaphore->Release(1, nullptr);
Wait(mutant.get(), false, 25ms);
mutant->Release();
});
std::vector<WaitHandle*> handles = {
mutant.get(),
semaphore.get(),
event_.get(),
thread.get(),
};
auto any_result = WaitAny(handles, false, 100ms);
REQUIRE(any_result.first == WaitResult::kSuccess);
REQUIRE(any_result.second == 0);
auto all_result = WaitAll(handles, false, 100ms);
REQUIRE(all_result == WaitResult::kSuccess);
} }
TEST_CASE("Signal and Wait") { TEST_CASE("Signal and Wait") {