[libcxx-commits] [libcxx] [libc++] fix `counting_semaphore` lost wakeups (PR #79265)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 2 08:57:25 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) {
----------------
ldionne wrote:

Thanks for the discussion. After discussing with @huixie90 , I understand better and I think

```c++
if (__old == 0) {
  __a_.notify_all();
}
```

is strictly better. I think avoiding an expensive syscall is probably most important. And our current implementation of `notify_one()` and `notify_all()` are actually the same right now, both do the equivalent of `notify_all()`. So the other alternative (`notify_all() / notify_one()`) doesn't save us anything.

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


More information about the libcxx-commits mailing list