The first change works around a compiler error in <mutex> in c++1y
mode, I think it's a front end bug (reported as PR 57573) but is easy
to solve with this change.
The second changes a test to avoid calling try_lock() when the calling
thread already owns the mutex, but moving the try_lock() call into a
new thread.
* include/std/mutex (call_once): Remove parentheses to fix error in
c++1y and gnu++1y mode.
* testsuite/30_threads/mutex/try_lock/2.cc: Call try_lock() in new
thread to avoid undefined behaviour.
Tested x86_64-linux, committed to trunk.
commit a548855f6c161971cd34b973dc9dc3c5b5663112
Author: Jonathan Wakely <[email protected]>
Date: Sun Jun 9 16:54:20 2013 +0100
* include/std/mutex (call_once): Remove parentheses to fix error in
c++1y and gnu++1y mode.
* testsuite/30_threads/mutex/try_lock/2.cc: Call try_lock() in new
thread to avoid undefined behaviour.
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 3c666c1..cdd05a3 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -783,7 +783,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__set_once_functor_lock_ptr(&__functor_lock);
#endif
- int __e = __gthread_once(&(__once._M_once), &__once_proxy);
+ int __e = __gthread_once(&__once._M_once, &__once_proxy);
#ifndef _GLIBCXX_HAVE_TLS
if (__functor_lock)
diff --git a/libstdc++-v3/testsuite/30_threads/mutex/try_lock/2.cc
b/libstdc++-v3/testsuite/30_threads/mutex/try_lock/2.cc
index bb3fcd4..f2a6723 100644
--- a/libstdc++-v3/testsuite/30_threads/mutex/try_lock/2.cc
+++ b/libstdc++-v3/testsuite/30_threads/mutex/try_lock/2.cc
@@ -24,6 +24,7 @@
#include <mutex>
+#include <thread>
#include <system_error>
#include <testsuite_hooks.h>
@@ -38,15 +39,18 @@ int main()
m.lock();
bool b;
- try
- {
- b = m.try_lock();
- VERIFY( !b );
- }
- catch (const std::system_error& e)
- {
- VERIFY( false );
- }
+ std::thread t([&] {
+ try
+ {
+ b = m.try_lock();
+ }
+ catch (const std::system_error& e)
+ {
+ VERIFY( false );
+ }
+ });
+ t.join();
+ VERIFY( !b );
m.unlock();
}