DRD: Add test program for std::thread.

To do: document _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE/AFTER in the DRD manual.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12284
This commit is contained in:
Bart Van Assche 2011-12-10 19:42:05 +00:00
parent a70a467080
commit aac70d3117
5 changed files with 88 additions and 0 deletions

View File

@ -1953,6 +1953,53 @@ AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_SECONDARY],
[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.
#----------------------------------------------------------------------------

View File

@ -219,6 +219,8 @@ EXTRA_DIST = \
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 @@ check_PROGRAMS += \
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 @@ endif
if HAVE_PTHREAD_BARRIER
matinv_LDADD = $(LDADD) -lm
endif
std_thread_SOURCES = std_thread.cpp
std_thread_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x

23
drd/tests/std_thread.cpp Normal file
View File

@ -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;
}

View File

@ -0,0 +1,4 @@
Done.
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

View File

@ -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