|
From: <sv...@va...> - 2011-12-10 19:46:46
|
Author: bart
Date: 2011-12-10 19:42:05 +0000 (Sat, 10 Dec 2011)
New Revision: 12284
Log:
DRD: Add test program for std::thread.
To do: document _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE/AFTER in the DRD manual.
Added:
trunk/drd/tests/std_thread.cpp
trunk/drd/tests/std_thread.stderr.exp
trunk/drd/tests/std_thread.vgtest
Modified:
trunk/configure.in
trunk/drd/tests/Makefile.am
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2011-12-10 16:06:57 UTC (rev 12283)
+++ trunk/configure.in 2011-12-10 19:42:05 UTC (rev 12284)
@@ -1953,6 +1953,53 @@
[test x$ac_enable_linux_ticket_lock_secondary = xyes])
+# does libstdc++ support annotating shared pointers ?
+AC_MSG_CHECKING([if libstdc++ supports annotating shared pointers])
+
+safe_CXXFLAGS=$CFLAGS
+CXXFLAGS="-std=c++0x"
+
+AC_LANG_PUSH(C++)
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ #include <memory>
+]], [[
+ std::shared_ptr<int> p
+]])], [
+ ac_have_shared_ptr=yes
+], [
+ ac_have_shared_ptr=no
+])
+if test x$ac_have_shared_ptr = xyes; then
+ # If compilation of the program below fails because of a syntax error
+ # triggered by substituting one of the annotation macros then that
+ # means that libstdc++ supports these macros.
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+ #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(a) (a)----
+ #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(a) (a)----
+ #include <memory>
+ ]], [[
+ std::shared_ptr<int> p
+ ]])], [
+ ac_have_shared_pointer_annotation=no
+ AC_MSG_RESULT([no])
+ ], [
+ ac_have_shared_pointer_annotation=yes
+ AC_MSG_RESULT([yes])
+ AC_DEFINE(HAVE_SHARED_POINTER_ANNOTATION, 1,
+ [Define to 1 if libstd++ supports annotating shared pointers])
+ ])
+else
+ ac_have_shared_pointer_annotation=no
+ AC_MSG_RESULT([no])
+fi
+AC_LANG_POP(C++)
+
+CXXFLAGS=$safe_CXXFLAGS
+
+AM_CONDITIONAL([HAVE_SHARED_POINTER_ANNOTATION],
+ [test x$ac_have_shared_pointer_annotation = xyes])
+
+
#----------------------------------------------------------------------------
# Ok. We're done checking.
#----------------------------------------------------------------------------
Modified: trunk/drd/tests/Makefile.am
===================================================================
--- trunk/drd/tests/Makefile.am 2011-12-10 16:06:57 UTC (rev 12283)
+++ trunk/drd/tests/Makefile.am 2011-12-10 19:42:05 UTC (rev 12284)
@@ -219,6 +219,8 @@
sigalrm.vgtest \
sigaltstack.stderr.exp \
sigaltstack.vgtest \
+ std_thread.stderr.exp \
+ std_thread.vgtest \
tc01_simple_race.stderr.exp \
tc01_simple_race.vgtest \
tc02_simple_tls.stderr.exp \
@@ -345,6 +347,11 @@
tsan_unittest
endif
+if HAVE_SHARED_POINTER_ANNOTATION
+check_PROGRAMS += \
+ std_thread
+endif
+
if HAVE_OPENMP
check_PROGRAMS += omp_matinv omp_prime omp_printf
endif
@@ -415,3 +422,6 @@
if HAVE_PTHREAD_BARRIER
matinv_LDADD = $(LDADD) -lm
endif
+
+std_thread_SOURCES = std_thread.cpp
+std_thread_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x
Added: trunk/drd/tests/std_thread.cpp
===================================================================
--- trunk/drd/tests/std_thread.cpp (rev 0)
+++ trunk/drd/tests/std_thread.cpp 2011-12-10 19:42:05 UTC (rev 12284)
@@ -0,0 +1,23 @@
+// Test whether no race conditions are reported on std::thread. Note: since
+// the implementation of std::thread uses the shared pointer implementation,
+// that implementation has to be annotated in order to avoid false positives.
+// See also http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html for more
+// information.
+
+#include "../../drd/drd.h"
+#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(addr) \
+ ANNOTATE_HAPPENS_BEFORE(addr)
+#define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(addr) \
+ ANNOTATE_HAPPENS_AFTER(addr)
+#define _GLIBCXX_EXTERN_TEMPLATE -1
+
+#include <iostream>
+#include <thread>
+
+int main(int argc, char** argv)
+{
+ std::thread t( []() { } );
+ t.join();
+ std::cerr << "Done.\n";
+ return 0;
+}
Added: trunk/drd/tests/std_thread.stderr.exp
===================================================================
--- trunk/drd/tests/std_thread.stderr.exp (rev 0)
+++ trunk/drd/tests/std_thread.stderr.exp 2011-12-10 19:42:05 UTC (rev 12284)
@@ -0,0 +1,4 @@
+
+Done.
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/std_thread.vgtest
===================================================================
--- trunk/drd/tests/std_thread.vgtest (rev 0)
+++ trunk/drd/tests/std_thread.vgtest 2011-12-10 19:42:05 UTC (rev 12284)
@@ -0,0 +1,4 @@
+prereq: test -e std_thread && ./supported_libpthread
+vgopts: --check-stack-var=yes --show-confl-seg=no
+prog: std_thread
+stderr_filter: filter_stderr
|