Issue |
95944
|
Summary |
[libc++][test] thread.condition.condvar/notify_all.pass.cpp has a flaky timing assumption
|
Labels |
libc++
|
Assignees |
|
Reporter |
StephanTLavavej
|
After #91530 refactored some condvar tests to pass reliably, @Arup-Chauhan helped MSVC's STL by re-enabling the condvar tests that we had been skipping (https://github.com/microsoft/STL/pull/4721). However, our CI system immediately encountered sporadic failures in `thread.condition.condvar/notify_all.pass.cpp`. #91530 didn't change that test, so this isn't new, we just didn't realize this had a distinct cause until the other tests were fixed.
The assertions we saw (on different test runs) were:
```
Assertion failed: test1 == 0, file D:\a\_work\1\s\llvm-project\libcxx\test\std\thread\thread.condition\thread.condition.condvar\notify_all.pass.cpp, line 35
Assertion failed: test2 == 0, file D:\a\_work\1\s\llvm-project\libcxx\test\std\thread\thread.condition\thread.condition.condvar\notify_all.pass.cpp, line 45
```
The test code is clearly using `sleep_for` 100ms as a synchronization primitive:
https://github.com/llvm/llvm-project/blob/3eb4128eb0cb4a42b912ee352c120a9c0f2ddbd6/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp#L32-L35
https://github.com/llvm/llvm-project/blob/3eb4128eb0cb4a42b912ee352c120a9c0f2ddbd6/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp#L42-L45
https://github.com/llvm/llvm-project/blob/3eb4128eb0cb4a42b912ee352c120a9c0f2ddbd6/libcxx/test/std/thread/thread.condition/thread.condition.condvar/notify_all.pass.cpp#L52-L61
Under heavy load, it's entirely possible for the new threads `t1` and `t2` running `f1` and `f2` respectively to not get started before the `main` thread gets through its 100ms sleep, acquires `mut`, and sets `test1` and `test2` to `1`. This causes `f1` and `f2` to assert when they discover this.
A deterministic mechanism needs to be used here.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs