@@ -256,7 +256,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__update > 1)
__atomic_notify_address_bare(&_M_counter, true);
else
- __atomic_notify_address_bare(&_M_counter, false);
+ __atomic_notify_address_bare(&_M_counter, true);
+// FIXME - Figure out why this does not wake a waiting thread
+// __atomic_notify_address_bare(&_M_counter, false);
}
private:
new file mode 100644
@@ -0,0 +1,77 @@
+// Copyright (C) 2020-2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a -pthread" }
+// { dg-do run { target c++2a } }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+// { dg-add-options libatomic }
+
+#include <array>
+#include <iostream>
+#include <sstream>
+
+#include <thread>
+#include <semaphore>
+#include <mutex>
+#include <chrono>
+#include <vector>
+
+std::counting_semaphore<4> semaphore{6};
+
+std::mutex mtx;
+std::vector<std::string> results;
+
+void thread_main(size_t x)
+{
+ semaphore.acquire();
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ semaphore.release();
+ {
+ std::ostringstream stm;
+ stm << "Thread " << x << " finished.";
+ std::lock_guard g{ mtx };
+ results.push_back(stm.str());
+ }
+}
+
+int main()
+{
+
+ constexpr auto nthreads = 10;
+
+ std::vector<std::thread> threads(nthreads);
+
+
+ size_t counter{0};
+ for(auto& t : threads)
+ {
+ t = std::thread(thread_main, counter++);
+ }
+
+ for(auto& t : threads)
+ {
+ t.join();
+ {
+ std::lock_guard g{ mtx };
+ for (auto&& r : results)
+ std::cout << r << '\n';
+ std::cout.flush();
+ results.clear();
+ }
+ }
+}