Skip to content

Commit 976ac12

Browse files
committed
Another adaption of Mutex.return_last_failed
The slow switching between threads may cause MSVC to return the index of a different lockable instead of the predicted. Signed-off-by: Ted Lyngmo <[email protected]>
1 parent 3e4b5cd commit 976ac12

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tests/beman/timed_lock_alg/mutex.test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ TEST(Mutex, return_last_failed) {
7878
auto th = JThread([&] {
7979
std::lock(mtxs[0], mtxs[1]);
8080
std::this_thread::sleep_for(10ms);
81-
mtxs[0].unlock(); // 5ms after try_lock_for started, 10ms left
81+
mtxs[0].unlock(); // 5ms after try_lock_for started, 15ms left
8282

8383
// try_lock_for here hangs on mtxs[1] and should return 1:
84-
std::this_thread::sleep_for(20ms);
84+
std::this_thread::sleep_for(20ms + extra_grace);
8585
mtxs[1].unlock();
8686
});
8787

8888
std::this_thread::sleep_for(5ms);
89-
EXPECT_EQ(1, std::apply([](auto&... mts) { return tla::try_lock_for(15ms, mts...); }, mtxs));
89+
EXPECT_EQ(1, std::apply([](auto&... mts) { return tla::try_lock_for(20ms, mts...); }, mtxs));
9090
}
9191

9292
TEST(Mutex, succeed_with_three_in_tricky_sequence) {

0 commit comments

Comments
 (0)