diff mbox

Fix std::try_lock behaviour

Message ID 20140922145434.GB2669@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Sept. 22, 2014, 2:54 p.m. UTC
When I fixed std::try_lock a few years ago I misread the spec,
exceptions should not be caught and turned into a return value.

Tested x86_64-linux, committed to trunk.

Comments

Jonathan Wakely Oct. 1, 2014, 12:36 p.m. UTC | #1
On 22/09/14 15:54 +0100, Jonathan Wakely wrote:
>When I fixed std::try_lock a few years ago I misread the spec,
>exceptions should not be caught and turned into a return value.
>
>Tested x86_64-linux, committed to trunk.

... and also the 4.9 branch.

>    	* include/std/mutex (try_lock): Do not swallow exceptions.
>    	* testsuite/30_threads/try_lock/4.cc: Fix test.
diff mbox

Patch

commit 5effca670aa009c60e31b639604da4d00f388038
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Sep 18 16:15:54 2014 +0100

    	* include/std/mutex (try_lock): Do not swallow exceptions.
    	* testsuite/30_threads/try_lock/4.cc: Fix test.

diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index f6b851c..d80fa5a 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -630,12 +630,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       int __idx;
       auto __locks = std::tie(__l1, __l2, __l3...);
-      __try
-      { __try_lock_impl<0>::__do_try_lock(__locks, __idx); }
-      __catch(const __cxxabiv1::__forced_unwind&)
-      { __throw_exception_again; }
-      __catch(...)
-      { }
+      __try_lock_impl<0>::__do_try_lock(__locks, __idx);
       return __idx;
     }
 
diff --git a/libstdc++-v3/testsuite/30_threads/try_lock/4.cc b/libstdc++-v3/testsuite/30_threads/try_lock/4.cc
index 7741798..1212b65 100644
--- a/libstdc++-v3/testsuite/30_threads/try_lock/4.cc
+++ b/libstdc++-v3/testsuite/30_threads/try_lock/4.cc
@@ -133,8 +133,15 @@  void test03()
       while (unreliable_lock::throw_on < 3)
       {
         unreliable_lock::count = 0;
-        int failed = std::try_lock(l1, l2, l3);
-        VERIFY( failed == unreliable_lock::throw_on );
+        try
+          {
+            std::try_lock(l1, l2, l3);
+            VERIFY( false );
+          }
+        catch (int e)
+          {
+            VERIFY( e == unreliable_lock::throw_on );
+          }
         ++unreliable_lock::throw_on;
       }
     }