[Bug libstdc++/121237] New: Wrong return value of `condition_variable_any::wait_until`
rohan at rohanlean dot de
gcc-bugzilla@gcc.gnu.org
Thu Jul 24 19:33:53 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121237
Bug ID: 121237
Summary: Wrong return value of
`condition_variable_any::wait_until`
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: rohan at rohanlean dot de
Target Milestone: ---
The `stop_token` overload of `condition_variable_any` can sometimes return a
wrong result. The implementation in [thread.condvarany.intwait], paragraph 7,
always returns `pred()`:
```
while (!stoken.stop_requested()) {
if (pred())
return true;
wait(lock);
}
return pred();
```
The libstdc++ implementation on the other hand can return `false` even if
`pred()` is `true`, if the wait is interrupted by the stop token:
```
while (!__p())
{
bool __stop;
{
unique_lock<mutex> __my_lock(*__mutex);
if (__stoken.stop_requested())
{
return false;
}
_Unlock<_Lock> __u(__lock);
unique_lock<mutex> __my_lock2(std::move(__my_lock));
const auto __status = _M_cond.wait_until(__my_lock2, __abs_time);
__stop = (__status == std::cv_status::timeout) ||
__stoken.stop_requested();
}
if (__stop)
{
return __p();
}
}
return true;
```
More information about the Gcc-bugs
mailing list