From: Julian Seward Date: Tue, 27 Nov 2007 01:59:38 +0000 (+0000) Subject: Translate the drd regtests from C++ to C. (Bart Van Assche). X-Git-Tag: svn/VALGRIND_3_3_0~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a219917dbfbad203a6a0416965f0abc9610c69c;p=thirdparty%2Fvalgrind.git Translate the drd regtests from C++ to C. (Bart Van Assche). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7238 --- diff --git a/exp-drd/tests/Makefile.am b/exp-drd/tests/Makefile.am index 365556a5f6..2959c5665f 100644 --- a/exp-drd/tests/Makefile.am +++ b/exp-drd/tests/Makefile.am @@ -34,39 +34,27 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_builddir)/include AM_CXXFLAGS = $(AM_CFLAGS) check_PROGRAMS = \ - abort \ fp_race \ - new_delete \ pth_broadcast \ pth_cond_race \ pth_create_chain \ pth_detached \ - sigalrm \ - std-string + sigalrm -abort_SOURCES = abort.cpp -abort_LDADD = -lpthread - -fp_race_SOURCES = fp_race.cpp +fp_race_SOURCES = fp_race.c fp_race_LDADD = -lpthread -new_delete_SOURCES = new_delete.cpp -new_delete_LDADD = -lpthread - -pth_broadcast_SOURCES = pth_broadcast.cpp +pth_broadcast_SOURCES = pth_broadcast.c pth_broadcast_LDADD = -lpthread -pth_cond_race_SOURCES = pth_cond_race.cpp +pth_cond_race_SOURCES = pth_cond_race.c pth_cond_race_LDADD = -lpthread -pth_create_chain_SOURCES = pth_create_chain.cpp +pth_create_chain_SOURCES = pth_create_chain.c pth_create_chain_LDADD = -lpthread pth_detached_SOURCES = pth_detached.c pth_detached_LDADD = -lpthread -sigalrm_SOURCES = sigalrm.cpp +sigalrm_SOURCES = sigalrm.c sigalrm_LDADD = -lpthread -lrt - -std_string_SOURCES = std-string.cpp -std_string_LDADD = -lpthread diff --git a/exp-drd/tests/abort.cpp b/exp-drd/tests/abort.cpp index 45d24014e7..e69de29bb2 100644 --- a/exp-drd/tests/abort.cpp +++ b/exp-drd/tests/abort.cpp @@ -1,37 +0,0 @@ -// assert(false) calls __assert_fail(), which in turn calls abort() and -// _IO_flush_all_lockp(). This last function triggers a race. Check that this -// race is suppressed. Note: the test program below is not sufficient for -// reproducing this race. - - -#include -#include -#include -#include -#include -static pthread_mutex_t s_mutex; - -void* thread_func(void*) -{ - pthread_mutex_lock(&s_mutex); - pthread_mutex_unlock(&s_mutex); - std::cout << "thread\n"; - assert(false); - return 0; -} - -int main(int argc, char** argv) -{ - pthread_mutex_init(&s_mutex, 0); - pthread_t tid; - pthread_mutex_lock(&s_mutex); - pthread_create(&tid, 0, thread_func, 0); - FILE* fp = fopen("/tmp/valgrind-drd-tests-abort", "w"); - fprintf(fp, "x"); - pthread_mutex_unlock(&s_mutex); - pthread_join(tid, 0); - pthread_mutex_destroy(&s_mutex); - fclose(fp); - - return 0; -} diff --git a/exp-drd/tests/fp_race.cpp b/exp-drd/tests/fp_race.c similarity index 83% rename from exp-drd/tests/fp_race.cpp rename to exp-drd/tests/fp_race.c index ad627cd717..79af162e46 100644 --- a/exp-drd/tests/fp_race.cpp +++ b/exp-drd/tests/fp_race.c @@ -24,8 +24,8 @@ // Test data race detection between floating point variables. -#include -#include // printf() +#include +#include // printf() #include #include // usleep() #include "../drd_clientreq.h" @@ -45,23 +45,9 @@ static double s_d1; // accessed before thread creation and in the created static double s_d2; // accessed in the created thread and after the join // (not a race). static double s_d3; // accessed simultaneously from both threads (race). -static bool s_debug = false; -static bool s_do_printf = false; -static bool s_use_mutex = false; - - -class CScopedLock -{ -public: - CScopedLock() - { if (s_use_mutex) pthread_mutex_lock(&s_mutex); } - ~CScopedLock() - { if (s_use_mutex) pthread_mutex_unlock(&s_mutex); } - -private: - CScopedLock(CScopedLock const&); - CScopedLock& operator=(CScopedLock const&); -}; +static int s_debug = 0; +static int s_do_printf = 0; +static int s_use_mutex = 0; // Function definitions. @@ -75,24 +61,26 @@ static void set_thread_name(const char* const name) int main(int argc, char** argv) { + int optchar; + pthread_t threadid; + set_thread_name("main"); - int optchar; while ((optchar = getopt(argc, argv, "dmp")) != EOF) { switch (optchar) { case 'd': - s_debug = true; + s_debug = 1; break; case 'm': - s_use_mutex = true; + s_use_mutex = 1; break; case 'p': - s_do_printf = true; + s_do_printf = 1; break; default: - assert(false); + assert(0); } } @@ -110,13 +98,13 @@ int main(int argc, char** argv) s_d1 = 1; s_d3 = 3; - pthread_t threadid; pthread_create(&threadid, 0, thread_func, 0); // Wait until the printf() in the created thread finished. { - CScopedLock ScopedLock; + if (s_use_mutex) pthread_mutex_lock(&s_mutex); s_d3++; + if (s_use_mutex) pthread_mutex_unlock(&s_mutex); } // Wait until the thread finished. @@ -133,7 +121,7 @@ int main(int argc, char** argv) return 0; } -static void* thread_func(void*) +static void* thread_func(void* thread_arg) { set_thread_name("thread_func"); @@ -143,8 +131,9 @@ static void* thread_func(void*) } s_d2 = 2; { - CScopedLock ScopedLock; + if (s_use_mutex) pthread_mutex_lock(&s_mutex); s_d3++; + if (s_use_mutex) pthread_mutex_unlock(&s_mutex); } return 0; } diff --git a/exp-drd/tests/fp_race.stderr.exp b/exp-drd/tests/fp_race.stderr.exp index d758083c8b..1a44269152 100644 --- a/exp-drd/tests/fp_race.stderr.exp +++ b/exp-drd/tests/fp_race.stderr.exp @@ -1,6 +1,6 @@ Conflicting load by main at 0x........ size 8 - at 0x........: main (fp_race.cpp:?) + at 0x........: main (fp_race.c:?) Allocation context: s_d3 (offset 0, size 8) in fp_race, NONE:BSS Other segment start (thread_func) (thread finished, call stack no longer available) @@ -8,7 +8,7 @@ Other segment end (thread_func) (thread finished, call stack no longer available) Conflicting store by main at 0x........ size 8 - at 0x........: main (fp_race.cpp:?) + at 0x........: main (fp_race.c:?) Allocation context: s_d3 (offset 0, size 8) in fp_race, NONE:BSS Other segment start (thread_func) (thread finished, call stack no longer available) diff --git a/exp-drd/tests/fp_race.stderr.exp2 b/exp-drd/tests/fp_race.stderr.exp2 index a05d8c9128..c9afafd7b1 100644 --- a/exp-drd/tests/fp_race.stderr.exp2 +++ b/exp-drd/tests/fp_race.stderr.exp2 @@ -1,6 +1,6 @@ Conflicting load by main at 0x........ size 8 - at 0x........: main (fp_race.cpp:?) + at 0x........: main (fp_race.c:?) Allocation context: unknown Other segment start (thread_func) (thread finished, call stack no longer available) @@ -8,7 +8,7 @@ Other segment end (thread_func) (thread finished, call stack no longer available) Conflicting store by main at 0x........ size 8 - at 0x........: main (fp_race.cpp:?) + at 0x........: main (fp_race.c:?) Allocation context: unknown Other segment start (thread_func) (thread finished, call stack no longer available) diff --git a/exp-drd/tests/new_delete.cpp b/exp-drd/tests/new_delete.cpp deleted file mode 100644 index 0f949c568c..0000000000 --- a/exp-drd/tests/new_delete.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -void* thread_func(void*) -{ - delete new int; - return 0; -} - -int main(int argc, char** argv) -{ - pthread_t tid; - std::cout << "main, before pthread_create()\n" << std::flush; - pthread_create(&tid, 0, thread_func, 0); - std::cout << "main, after pthread_create()\n" << std::flush; - delete new int; - std::cout << "main, before pthread_join()\n" << std::flush; - pthread_join(tid, 0); - std::cout << "main, after pthread_join()\n" << std::flush; - return 0; -} diff --git a/exp-drd/tests/pth_broadcast.c b/exp-drd/tests/pth_broadcast.c new file mode 100644 index 0000000000..01111e52d0 --- /dev/null +++ b/exp-drd/tests/pth_broadcast.c @@ -0,0 +1,175 @@ +// Broadcast a (POSIX threads) signal to all running threads, where the +// number of threads can be specified on the command line. This test program +// is intended not only to test the correctness of drd but also to test +// whether performance does not degrade too much when the number of threads +// increases. + + +#include +#include +#include +#include +#include +#include + + +// Counting semaphore. + +struct csema +{ + pthread_mutex_t m_mutex; + pthread_cond_t m_cond; + int m_count; +}; + +void csema_ctr(struct csema* p) +{ + memset(p, 0, sizeof(*p)); + pthread_mutex_init(&p->m_mutex, 0); + pthread_cond_init(&p->m_cond, 0); +} + +void csema_dtr(struct csema* p) +{ + pthread_cond_destroy(&p->m_cond); + pthread_mutex_destroy(&p->m_mutex); +} + +void csema_p(struct csema* p, const int n) +{ + pthread_mutex_lock(&p->m_mutex); + while (p->m_count < n) + pthread_cond_wait(&p->m_cond, &p->m_mutex); + p->m_count -= n; + pthread_cond_signal(&p->m_cond); + pthread_mutex_unlock(&p->m_mutex); +} + +void csema_v(struct csema* p) +{ + pthread_mutex_lock(&p->m_mutex); + p->m_count++; + pthread_cond_signal(&p->m_cond); + pthread_mutex_unlock(&p->m_mutex); +} + + +struct cthread +{ + pthread_t m_thread; + int m_threadnum; + struct csema* m_sema; +}; + +void cthread_ctr(struct cthread* p) +{ + p->m_thread = 0; + p->m_sema = 0; +} + +void cthread_dtr(struct cthread* p) +{ } + + +// Local variables. + +static int s_debug = 0; +static int s_trace = 0; +static int s_signal_count; +static pthread_mutex_t s_mutex; +static pthread_cond_t s_cond; + + +// Function definitions. + +static void thread_func(struct cthread* thread_info) +{ + int i; + + pthread_mutex_lock(&s_mutex); + + for (i = 0; i < s_signal_count; i++) + { + if (s_trace) + { + printf("thread %d [%d] (1)\n", thread_info->m_threadnum, i); + } + csema_v(thread_info->m_sema); + + // Wait until the main thread signals us via pthread_cond_broadcast(). + pthread_cond_wait(&s_cond, &s_mutex); + if (s_trace) + { + printf("thread %d [%d] (2)\n", thread_info->m_threadnum, i); + } + } + + pthread_mutex_unlock(&s_mutex); +} + +int main(int argc, char** argv) +{ + int optchar; + int thread_count; + + while ((optchar = getopt(argc, argv, "d")) != EOF) + { + switch (optchar) + { + case 'd': + s_debug = 1; + break; + default: + assert(0); + break; + } + } + s_signal_count = argc > optind ? atoi(argv[optind]) : 10; + thread_count = argc > optind + 1 ? atoi(argv[optind + 1]) : 10; + + if (s_debug) + printf("&s_cond = %p\n", &s_cond); + + pthread_mutex_init(&s_mutex, 0); + pthread_cond_init(&s_cond, 0); + { + int i; + struct csema sema; + struct cthread* p; + struct cthread* thread_vec; + + csema_ctr(&sema); + thread_vec = malloc(sizeof(struct cthread) * thread_count); + for (p = thread_vec; p != thread_vec + thread_count; p++) + { + cthread_ctr(p); + p->m_threadnum = p - thread_vec; + p->m_sema = &sema; + pthread_create(&p->m_thread, 0, + (void*(*)(void*))thread_func, &*p); + } + for (i = 0; i < s_signal_count; i++) + { + if (s_trace) + printf("main [%d] (1)\n", i); + csema_p(&sema, thread_count); + if (s_trace) + printf("main [%d] (2)\n", i); + pthread_mutex_lock(&s_mutex); + pthread_cond_broadcast(&s_cond); + pthread_mutex_unlock(&s_mutex); + if (s_trace) + printf("main [%d] (3)\n", i); + } + for (i = 0; i < thread_count; i++) + { + pthread_join(thread_vec[i].m_thread, 0); + cthread_dtr(&thread_vec[i]); + } + free(thread_vec); + csema_dtr(&sema); + } + pthread_cond_destroy(&s_cond); + pthread_mutex_destroy(&s_mutex); + return 0; +} diff --git a/exp-drd/tests/pth_broadcast.cpp b/exp-drd/tests/pth_broadcast.cpp deleted file mode 100644 index a081de0218..0000000000 --- a/exp-drd/tests/pth_broadcast.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// Broadcast a (POSIX threads) signal to all running threads, where the -// number of threads can be specified on the command line. This test program -// is intended not only to test the correctness of drd but also to test -// whether performance does not degrade too much when the number of threads -// increases. - - -#include -#include -#include -#include -#include - -// Class definitions. - -// Counting semaphore. - -class CSema -{ -public: - CSema() - : m_mutex(), m_cond(), m_count(0) - { - pthread_mutex_init(&m_mutex, 0); - pthread_cond_init(&m_cond, 0); - } - ~CSema() - { - pthread_cond_destroy(&m_cond); - pthread_mutex_destroy(&m_mutex); - } - void p(const int n) - { - pthread_mutex_lock(&m_mutex); - while (m_count < n) - pthread_cond_wait(&m_cond, &m_mutex); - m_count -= n; - pthread_cond_signal(&m_cond); - pthread_mutex_unlock(&m_mutex); - } - void v() - { - pthread_mutex_lock(&m_mutex); - m_count++; - pthread_cond_signal(&m_cond); - pthread_mutex_unlock(&m_mutex); - } - -private: - CSema(CSema const&); - CSema& operator=(CSema const&); - - pthread_mutex_t m_mutex; - pthread_cond_t m_cond; - int m_count; -}; - -struct CThread -{ - CThread() - : m_thread(), m_sema() - { } - ~CThread() - { } - - pthread_t m_thread; - int m_threadnum; - CSema* m_sema; -}; - - -// Local variables. - -static bool s_debug = false; -static bool s_trace = false; -static int s_signal_count; -static pthread_mutex_t s_mutex; -static pthread_cond_t s_cond; - - -// Function definitions. - -static void thread_func(CThread* thread_info) -{ - pthread_mutex_lock(&s_mutex); - - for (int i = 0; i < s_signal_count; i++) - { - if (s_trace) - { - std::cout << "thread " << thread_info->m_threadnum - << " [" << i << "] (1)" << std::endl; - } - thread_info->m_sema->v(); - - // Wait until the main thread signals us via pthread_cond_broadcast(). - pthread_cond_wait(&s_cond, &s_mutex); - if (s_trace) - { - std::cout << "thread " << thread_info->m_threadnum - << " [" << i << "] (2)" << std::endl; - } - } - - pthread_mutex_unlock(&s_mutex); -} - -int main(int argc, char** argv) -{ - int optchar; - while ((optchar = getopt(argc, argv, "d")) != EOF) - { - switch (optchar) - { - case 'd': - s_debug = true; - break; - default: - assert(false); - break; - } - } - s_signal_count = argc > optind ? atoi(argv[optind]) : 10; - const int thread_count = argc > optind + 1 ? atoi(argv[optind + 1]) : 10; - - if (s_debug) - std::cout << "&s_cond = " << &s_cond << std::endl; - - pthread_mutex_init(&s_mutex, 0); - pthread_cond_init(&s_cond, 0); - { - CSema sema; - std::vector thread_vec(thread_count); - for (std::vector::iterator p = thread_vec.begin(); - p != thread_vec.end(); p++) - { - p->m_threadnum = std::distance(thread_vec.begin(), p); - p->m_sema = &sema; - pthread_create(&p->m_thread, 0, - (void*(*)(void*))thread_func, &*p); - } - for (int i = 0; i < s_signal_count; i++) - { - if (s_trace) - std::cout << "main [" << i << "] (1)\n"; - sema.p(thread_count); - if (s_trace) - std::cout << "main [" << i << "] (2)\n"; - pthread_mutex_lock(&s_mutex); - pthread_cond_broadcast(&s_cond); - pthread_mutex_unlock(&s_mutex); - if (s_trace) - std::cout << "main [" << i << "] (3)\n"; - } - for (int i = 0; i < thread_count; i++) - { - pthread_join(thread_vec[i].m_thread, 0); - } - } - pthread_cond_destroy(&s_cond); - pthread_mutex_destroy(&s_mutex); - return 0; -} diff --git a/exp-drd/tests/pth_cond_race.cpp b/exp-drd/tests/pth_cond_race.c similarity index 75% rename from exp-drd/tests/pth_cond_race.cpp rename to exp-drd/tests/pth_cond_race.c index 5eed2096c7..367d585c48 100644 --- a/exp-drd/tests/pth_cond_race.cpp +++ b/exp-drd/tests/pth_cond_race.c @@ -2,8 +2,8 @@ variable. By Bart Van Assche. */ -#include -#include // printf() +#include +#include // printf() #include #include // usleep() #include "../drd_clientreq.h" @@ -11,28 +11,14 @@ // Local functions declarations. -static void* thread_func(void*); +static void* thread_func(void* thread_arg); // Local variables. static pthread_mutex_t s_mutex; static pthread_cond_t s_cond; -static bool s_use_mutex = false; - - -class CScopedLock -{ -public: - CScopedLock() - { if (s_use_mutex) pthread_mutex_lock(&s_mutex); } - ~CScopedLock() - { if (s_use_mutex) pthread_mutex_unlock(&s_mutex); } - -private: - CScopedLock(CScopedLock const&); - CScopedLock& operator=(CScopedLock const&); -}; +static int s_use_mutex = 0; // Function definitions. @@ -46,18 +32,20 @@ static void set_thread_name(const char* const name) int main(int argc, char** argv) { + int optchar; + pthread_t threadid; + set_thread_name("main"); - int optchar; while ((optchar = getopt(argc, argv, "m")) != EOF) { switch (optchar) { case 'm': - s_use_mutex = true; + s_use_mutex = 1; break; default: - assert(false); + assert(0); } } @@ -65,7 +53,6 @@ int main(int argc, char** argv) pthread_mutex_init(&s_mutex, 0); pthread_mutex_lock(&s_mutex); - pthread_t threadid; pthread_create(&threadid, 0, thread_func, 0); pthread_cond_wait(&s_cond, &s_mutex); @@ -79,7 +66,7 @@ int main(int argc, char** argv) return 0; } -static void* thread_func(void*) +static void* thread_func(void* thread_arg) { set_thread_name("thread_func"); diff --git a/exp-drd/tests/pth_cond_race.stderr.exp b/exp-drd/tests/pth_cond_race.stderr.exp index 489ab983c4..47d3224b56 100644 --- a/exp-drd/tests/pth_cond_race.stderr.exp +++ b/exp-drd/tests/pth_cond_race.stderr.exp @@ -2,7 +2,7 @@ Thread 2: Race condition: condition variable 0x........ has been signalled but the associated mutex 0x........ is not locked by the signalling thread at 0x........: pthread_cond_signal@* (drd_preloaded.c:?) - by 0x........: thread_func(void*) (pth_cond_race.cpp:?) + by 0x........: thread_func (pth_cond_race.c:?) by 0x........: vg_thread_wrapper (drd_preloaded.c:?) by 0x........: start_thread (in libpthread-?.?.so) by 0x........: clone (in /...libc...) diff --git a/exp-drd/tests/pth_create_chain.cpp b/exp-drd/tests/pth_create_chain.c similarity index 84% rename from exp-drd/tests/pth_create_chain.cpp rename to exp-drd/tests/pth_create_chain.c index ab3dc84959..50242fa308 100644 --- a/exp-drd/tests/pth_create_chain.cpp +++ b/exp-drd/tests/pth_create_chain.c @@ -1,17 +1,19 @@ // Create threads in such a way that there is a realistic chance that the // parent thread finishes before the created thread finishes. -#include -#include -#include + +#include +#include +#include #include + static pthread_t s_thread[1000]; static int s_arg[1000]; static void* thread_func(void* p) { - int thread_count = *reinterpret_cast(p); + int thread_count = *(int*)(p); if (thread_count > 0) { thread_count--; @@ -29,18 +31,21 @@ static void* thread_func(void* p) int main(int argc, char** argv) { - unsigned thread_count = argc > 1 ? atoi(argv[1]) : 50; + int thread_count; + int i; + + thread_count = argc > 1 ? atoi(argv[1]) : 50; assert(thread_count <= sizeof(s_thread) / sizeof(s_thread[0])); assert(thread_count >= 1); thread_count--; // std::cout << "create " << thread_count << std::endl; pthread_create(&s_thread[thread_count], 0, thread_func, - const_cast(&thread_count)); + &thread_count); #if 0 std::cout << "created " << thread_count << "(" << s_thread[thread_count] << ")" << std::endl; #endif - for (int i = thread_count; i >= 0; i--) + for (i = thread_count; i >= 0; i--) { // std::cout << "join " << i << "(" << s_thread[i] << ")" << std::endl; pthread_join(s_thread[i], 0); diff --git a/exp-drd/tests/sigalrm.cpp b/exp-drd/tests/sigalrm.c similarity index 50% rename from exp-drd/tests/sigalrm.cpp rename to exp-drd/tests/sigalrm.c index 73a2c43186..e5d986849a 100644 --- a/exp-drd/tests/sigalrm.cpp +++ b/exp-drd/tests/sigalrm.c @@ -1,31 +1,17 @@ -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include -#include +#include +#include #include -#include "../drd_clientreq.h" +#include +#include #include +#include "../drd_clientreq.h" -#if !defined(__GLIBC_PREREQ) -# error "This program requires __GLIBC_PREREQ (in /usr/include/features.h)" -#endif - -#if __GLIBC_PREREQ(2,3) - -#define VALGRIND_START_NEW_SEGMENT \ -{ \ - int res; \ - VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_START_NEW_SEGMENT, \ - pthread_self(), 0, 0,0,0); \ -} -static bool s_debug = false; +static int s_debug = 0; static int getktid() @@ -52,34 +38,40 @@ static void SignalHandler(const int iSignal) } } -void* thread_func(void*) +void* thread_func(void* thread_arg) { + struct timespec tsRemain, tsDelay; + if (s_debug) { - std::cout << "thread: kernel thread ID " << getktid() - << " / Valgrind thread ID " << getvgtid() << "\n"; + printf("thread: kernel thread ID %d / Valgrind thread ID %d\n", + getktid(), getvgtid()); } - const timespec tsDelay = { 10, 0 }; - timespec tsRemain; + tsDelay.tv_sec = 10; + tsDelay.tv_nsec = 0; clock_nanosleep(CLOCK_MONOTONIC, 0, &tsDelay, &tsRemain); //assert(result < 0 && errno == EINTR); return 0; } -int main(int argc, char** ) +int main(int argc, char** argv) { + int vgthreadid; + pthread_t threadid; + struct timespec tsDelay; + // Primitive argument parsing. if (argc > 1) - s_debug = true; + s_debug = 1; - const int vgthreadid = getvgtid(); + vgthreadid = getvgtid(); if (s_debug) { - std::cout << "main: kernel thread ID " << getktid() - << " / Valgrind thread ID " << vgthreadid << std::endl; + printf("main: kernel thread ID %d / Valgrind thread ID %d\n", + getktid(), vgthreadid); } { @@ -90,10 +82,10 @@ int main(int argc, char** ) sigaction(SIGALRM, &sa, 0); } - pthread_t threadid; pthread_create(&threadid, 0, thread_func, 0); // Wait until the thread is inside clock_nanosleep(). - const timespec tsDelay = { 0, 20 * 1000 * 1000 }; + tsDelay.tv_sec = 0; + tsDelay.tv_nsec = 20 * 1000 * 1000; clock_nanosleep(CLOCK_MONOTONIC, 0, &tsDelay, 0); // And send SIGALRM to the thread. pthread_kill(threadid, SIGALRM); @@ -101,13 +93,3 @@ int main(int argc, char** ) return 0; } - -#else /* !__GLIBC_PREREQ(2,3) */ - -int main(int argc, char** ) -{ - std::cout << "program does not work on glibc < 2.3" << std::endl; - return 0; -} - -#endif /* __GLIBC_PREREQ(2,3) */ diff --git a/exp-drd/tests/std-string.cpp b/exp-drd/tests/std-string.cpp deleted file mode 100644 index 1d4d0d6656..0000000000 --- a/exp-drd/tests/std-string.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Note: the code below is not yet sufficient for reproducing the race on -// basic_string<>::_Rep_base::_M_refcount - - -#include -#include -#include -#include - - -static std::string s_string; - -static void* thread_func(void*) -{ - std::cout << "thread: string = " << s_string << std::endl; - return 0; -} - -int main(int argc, char** argv) -{ - const bool detached = argc <= 1; - - s_string = "(allocated by main thread)"; - - pthread_t tid; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, - detached - ? PTHREAD_CREATE_DETACHED - : PTHREAD_CREATE_JOINABLE); - pthread_create(&tid, &attr, thread_func, 0); - pthread_attr_destroy(&attr); - - std::cout << std::flush; - - if (detached) - sleep(1); - else - pthread_join(tid, 0); - - std::cout << std::flush; - - return 0; -} diff --git a/glibc-2.X-drd.supp b/glibc-2.X-drd.supp index 7c0e66824a..74625386a9 100644 --- a/glibc-2.X-drd.supp +++ b/glibc-2.X-drd.supp @@ -74,7 +74,7 @@ exp-drd:ConflictingAccess fun:start_thread fun:clone -} +} { pthread exp-drd:ConflictingAccess