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

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 17 13:56:52 PST 2021


Quuxplusone added a subscriber: ldionne.
Quuxplusone added a comment.

I believe the old code had a problem. I'm not fully convinced that the new code //doesn't// still have a similar problem. ;) But this PR seems like a good idea to me, and might even be a candidate for 13.x (@ldionne?).
Is it possible to write a very naïve test for this? E.g.

  int main(int, char**)
  {
      std::counting_semaphore s(0);
      std::barrier b(3);
      std::thread t1 = std::thread([&]() {
          for (int i=0; i < 100000; ++i) {
              s.acquire();
              b.arrive_and_wait();
          }
      });
      std::thread t2 = std::thread([&]() {
          for (int i=0; i < 100000; ++i) {
              s.acquire();
              b.arrive_and_wait();
          }
      });
      std::thread t3 = std::thread([&]() {
          for (int i=0; i < 100000; ++i) {
              s.release(1);
              s.release(1);
              b.arrive_and_wait();
          }
      });
      t1.join();
      t2.join();
      t3.join();
  
      return 0;
  }

(This fails to reproduce the problem on my personal laptop, but I don't think that's too surprising.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114119/new/

https://reviews.llvm.org/D114119



More information about the libcxx-commits mailing list