[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
Mon Jul 21 08:16:33 PDT 2025
================
@@ -188,9 +188,10 @@ public:
_LIBCPP_HIDE_FROM_ABI cv_status wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t) {
shared_ptr<mutex> __mut = __mut_;
unique_lock<mutex> __lk(*__mut);
+ const chrono::time_point<_Clock, _Duration> __t_local = __t;
----------------
johnsheu wrote:
What do you mean by "observable" here? The specification is for the call to `wait_until()` to take the timeout by-const-ref, so taking it by-value would be nonconforming. Note though that since `time_point` is also specified to have a copy constructor, changing the specification take it directly by-value would not break existing code.
If you mean taking the timeout by-const-ref and then making a value copy internally: I think that would be conforming, and would be unconditionally possible due to the `time_point` copy constructor. However, it would make an observable difference from current behavior:
- **Current behavior:** reducing `timeout` while call is blocked may result in "spurious" timeout
- **New behavior:** reducing `timeout` while call is blocked will not change timeout; value at the time the call was made will be used
As far as I can tell, both behaviors are technically permissible under the standard.
https://github.com/llvm/llvm-project/pull/148330
More information about the libcxx-commits
mailing list