[libcxx-commits] [libcxx] [libc++] fix `counting_semaphore` lost wakeups (PR #79265)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jan 31 06:47:00 PST 2024
================
@@ -95,19 +96,22 @@ public:
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__update <= _LIBCPP_SEMAPHORE_MAX - __old, "update is greater than the expected value");
- if (__old > 0) {
- // Nothing to do
- } else if (__update > 1)
+ if (__old == 0) {
----------------
huixie90 wrote:
So we can either do
```
if (__old == 0) {
__a_.notify_all();
}
```
or as you suggested
```
if (__update > 1)
__a_.notify_all();
else
__a_.notify_one();
```
Both of them would solve the original lost wake up described in
https://bugs.llvm.org/show_bug.cgi?id=47013
It seems like that it is a trade off between
1. we don't need to notify anyone unless our counter reaches 0
2. we can just notify one thread if the caller passed `__update == 1`
https://github.com/llvm/llvm-project/pull/79265
More information about the libcxx-commits
mailing list