public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089]
@ 2023-10-26 20:11 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-10-26 20:11 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk. Worth backporting to all active
branches, I think.

-- >8 --

The incorrect errc constant here looks like a copy&paste error.

libstdc++-v3/ChangeLog:

	PR libstdc++/112089
	* include/std/shared_mutex (shared_lock::unlock): Change errc
	constant to operation_not_permitted.
	* testsuite/30_threads/shared_lock/locking/112089.cc: New test.
---
 libstdc++-v3/include/std/shared_mutex         |  2 +-
 .../30_threads/shared_lock/locking/112089.cc  | 23 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc

diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex
index 4f236a19806..f205c36533b 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -820,7 +820,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       unlock()
       {
 	if (!_M_owns)
-	  __throw_system_error(int(errc::resource_deadlock_would_occur));
+	  __throw_system_error(int(errc::operation_not_permitted));
 	_M_pm->unlock_shared();
 	_M_owns = false;
       }
diff --git a/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc
new file mode 100644
index 00000000000..432c17591a1
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc
@@ -0,0 +1,23 @@
+// { dg-do run { target c++14 } }
+// { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+
+#include <shared_mutex>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+// PR libstdc++/112089 shared_lock::unlock should throw operation_not_permitted
+
+int main()
+{
+  std::shared_lock<std::shared_timed_mutex> l;
+  try
+  {
+    l.unlock();
+    VERIFY( false );
+  }
+  catch (const std::system_error& e)
+  {
+    VERIFY( e.code() == std::errc::operation_not_permitted );
+  }
+}
-- 
2.41.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-26 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26 20:11 [committed] libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).