Patchwork libstdc++/50862 fix deadlock in condition_variable_any

login
register
mail settings
Submitter Jonathan Wakely
Date Oct. 26, 2011, 11:37 p.m.
Message ID <CAH6eHdS++3Mkqxx9o7Tq61o3pCXn7krSigbMieseN6Wh09NAXA@mail.gmail.com>
Download mbox | patch
Permalink /patch/122038/
State New
Headers show

Comments

Jonathan Wakely - Oct. 26, 2011, 11:37 p.m.
PR libstdc++/50862
        * include/std/condition_variable (condition_variable_any::wait): Avoid
        terminating if relocking user mutex throws during stack-unwinding.
        * testsuite/30_threads/condition_variable_any/50862.cc: Add dg-require.

Fixes two more issues pointed out in the PR comments.

Tested x86_64-linux, committed to trunk.

Patch

Index: include/std/condition_variable
===================================================================
--- include/std/condition_variable	(revision 180456)
+++ include/std/condition_variable	(working copy)
@@ -205,7 +205,13 @@ 
 	// scoped unlock - unlocks in ctor, re-locks in dtor
 	struct _Unlock {
 	  explicit _Unlock(_Lock& __lk) : _M_lock(__lk) { __lk.unlock(); }
-	  ~_Unlock() { _M_lock.lock(); }
+	  ~_Unlock() noexcept(false)
+	  {
+	    if (uncaught_exception())
+	      __try { _M_lock.lock(); } __catch(...) { }
+	    else
+	      _M_lock.lock();
+	  }
 	  _Lock& _M_lock;
 	};
 
Index: testsuite/30_threads/condition_variable_any/50862.cc
===================================================================
--- testsuite/30_threads/condition_variable_any/50862.cc	(revision 180456)
+++ testsuite/30_threads/condition_variable_any/50862.cc	(working copy)
@@ -4,6 +4,7 @@ 
 // { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
+// { dg-require-sched-yield "" }
  
 // Copyright (C) 2011 Free Software Foundation, Inc.
 //