[libcxx-commits] [libcxx] [libc++] Save duration/timeout locally for condition_variable waits (PR #148330)

John Sheu via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 12 04:04:10 PDT 2025


johnsheu wrote:

To answer (2) above first:
```shell
sheu at sheu-mac ~ % clang++ -o cv_wait_until cv_wait_until.cc  -std=c++20 && ./cv_wait_until
timeout
```
Even though `timeout` is `time_point::max()` at the point that `cv.wait_until()` is invoked (which should cause no timeout on wakeup), the later change to `time_point::min()` causes the wait to report that the timeout occurred.  Note that from the point of view of the programmer, `timeout` is itself properly locked.

To answer (1), the program is well-formed in the case that `std::condition_variable` is used, it just has unexpected behavior.  However, in the case that `std::condition_variable_any` is used instead, _the program is ill-formed_, as the implementation actually unlocks the lock _and then accesses_ `timeout`, causing a data race.  This could be considered an actual bug in libc++ implementation.

https://github.com/llvm/llvm-project/pull/148330


More information about the libcxx-commits mailing list