|
From: <sv...@va...> - 2014-06-09 09:01:55
|
Author: bart
Date: Mon Jun 9 09:01:46 2014
New Revision: 14014
Log:
drd/tests/std_thread2: Add
Added:
trunk/drd/tests/std_thread2.cpp
trunk/drd/tests/std_thread2.stderr.exp
trunk/drd/tests/std_thread2.vgtest
Modified:
trunk/drd/tests/Makefile.am
Modified: trunk/drd/tests/Makefile.am
==============================================================================
--- trunk/drd/tests/Makefile.am (original)
+++ trunk/drd/tests/Makefile.am Mon Jun 9 09:01:46 2014
@@ -254,6 +254,8 @@
std_string.vgtest \
std_thread.stderr.exp \
std_thread.vgtest \
+ std_thread2.stderr.exp \
+ std_thread2.vgtest \
str_tester.stderr.exp \
str_tester.vgtest \
tc01_simple_race.stderr.exp \
@@ -399,7 +401,8 @@
std_atomic \
std_list \
std_string \
- std_thread
+ std_thread \
+ std_thread2
endif
endif
@@ -493,4 +496,7 @@
std_thread_SOURCES = std_thread.cpp
std_thread_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x
+std_thread2_SOURCES = std_thread2.cpp
+std_thread2_CXXFLAGS = $(AM_CXXFLAGS) -std=c++0x
+
sem_wait_SOURCES = sem_wait.cpp
Added: trunk/drd/tests/std_thread2.cpp
==============================================================================
--- trunk/drd/tests/std_thread2.cpp (added)
+++ trunk/drd/tests/std_thread2.cpp Mon Jun 9 09:01:46 2014
@@ -0,0 +1,72 @@
+// 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)
+
+#include <iostream>
+#include <thread>
+#include <unistd.h>
+
+static int i;
+
+int main(int argc, char** argv)
+{
+ std::thread t1( []() { sleep(1); i = 1; } );
+ std::thread t2( []() { i = 2; } );
+ t2.join();
+ t1.join();
+ std::cerr << "Done.\n";
+ return 0;
+}
+
+//
+// From libstdc++-v3/src/c++11/thread.cc
+//
+
+extern "C" void* execute_native_thread_routine(void* __p)
+{
+ std::thread::_Impl_base* __t = static_cast<std::thread::_Impl_base*>(__p);
+ std::thread::__shared_base_type __local;
+ __local.swap(__t->_M_this_ptr);
+
+ __try {
+ __t->_M_run();
+ } __catch(const __cxxabiv1::__forced_unwind&) {
+ __throw_exception_again;
+ } __catch(...) {
+ std::terminate();
+ }
+
+ return 0;
+}
+
+#include <system_error>
+
+namespace std
+{
+ void thread::_M_start_thread(__shared_base_type __b)
+ {
+ if (!__gthread_active_p())
+#if __EXCEPTIONS
+ throw system_error(make_error_code(errc::operation_not_permitted),
+ "Enable multithreading to use std::thread");
+#else
+ __throw_system_error(int(errc::operation_not_permitted));
+#endif
+
+ __b->_M_this_ptr = __b;
+ int __e = __gthread_create(&_M_id._M_thread, execute_native_thread_routine,
+ __b.get());
+ if (__e) {
+ __b->_M_this_ptr.reset();
+ __throw_system_error(__e);
+ }
+ }
+}
Added: trunk/drd/tests/std_thread2.stderr.exp
==============================================================================
--- trunk/drd/tests/std_thread2.stderr.exp (added)
+++ trunk/drd/tests/std_thread2.stderr.exp Mon Jun 9 09:01:46 2014
@@ -0,0 +1,13 @@
+
+Thread 2:
+Conflicting store by thread 2 at 0x........ size 4
+ at 0x........: main::{lambda()#1}::operator()() const (std_thread2.cpp:21)
+ by 0x........: void std::_Bind_simple<main::{lambda()#1} ()>::_M_invoke<>(std::_Index_tuple<>) (functional:1732)
+ by 0x........: std::_Bind_simple<main::{lambda()#1} ()>::operator()() (functional:1720)
+ by 0x........: std::thread::_Impl<std::_Bind_simple<main::{lambda()#1} ()> >::_M_run() (thread:115)
+ by 0x........: execute_native_thread_routine (std_thread2.cpp:40)
+Allocation context: BSS section of std_thread2
+
+Done.
+
+ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/std_thread2.vgtest
==============================================================================
--- trunk/drd/tests/std_thread2.vgtest (added)
+++ trunk/drd/tests/std_thread2.vgtest Mon Jun 9 09:01:46 2014
@@ -0,0 +1,4 @@
+prereq: test -e std_thread2 && ./supported_libpthread
+vgopts: --check-stack-var=yes --show-confl-seg=no --num-callers=5
+prog: std_thread2
+stderr_filter: filter_stderr
|