[libcxx-commits] [PATCH] D114119: [libcxx] Fix potential lost wake-up in counting semaphore

Fabian Wolff via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 17 13:31:05 PST 2021


fwolff created this revision.
fwolff added reviewers: Quuxplusone, libc++.
fwolff added a project: libc++.
fwolff requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

Fixes PR#47013 <https://bugs.llvm.org/show_bug.cgi?id=47013>. The implementation in libstdc++ seems to have had the same problem (see Bug #100806 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806>) and also solved it by always notifying all (instead of just one if `__update` is equal to 1).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114119

Files:
  libcxx/include/semaphore


Index: libcxx/include/semaphore
===================================================================
--- libcxx/include/semaphore
+++ libcxx/include/semaphore
@@ -87,10 +87,9 @@
     {
         if(0 < __a.fetch_add(__update, memory_order_release))
             ;
-        else if(__update > 1)
-            __a.notify_all();
         else
-            __a.notify_one();
+            // Always notify all, regardless of the value of __update (see PR47013)
+            __a.notify_all();
     }
     _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
     void acquire()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114119.388017.patch
Type: text/x-patch
Size: 569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211117/e779a463/attachment-0001.bin>


More information about the libcxx-commits mailing list