]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests/atomic_var: Avoid that platform-specific code can trigger a false negative
authorBart Van Assche <bvanassche@acm.org>
Tue, 18 Mar 2014 08:45:51 +0000 (08:45 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 18 Mar 2014 08:45:51 +0000 (08:45 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13876

drd/tests/atomic_var.c
drd/tests/atomic_var.stderr.exp
drd/tests/atomic_var.vgtest

index 40f15669e3d9d6b929c18e9cd2372330017fb682..113a3a50b1a49cf0043b40f20ab3a6b7dc3e41c8 100644 (file)
@@ -23,6 +23,8 @@
 has built-in functions for atomic memory access.
 #endif
 
+static pthread_barrier_t s_barrier;
+
 static __inline__
 int sync_add_and_fetch(int* p, int i)
 {
@@ -36,6 +38,7 @@ static int s_y = 0;
 
 static void* thread_func_1(void* arg)
 {
+  pthread_barrier_wait(&s_barrier);
   s_y = 1;
   (void) sync_add_and_fetch(&s_x, 1);
   return 0;
@@ -43,6 +46,7 @@ static void* thread_func_1(void* arg)
 
 static void* thread_func_2(void* arg)
 {
+  pthread_barrier_wait(&s_barrier);
   while (sync_add_and_fetch(&s_x, 0) == 0)
     ;
   fprintf(stderr, "y = %d\n", s_y);
@@ -56,10 +60,12 @@ int main(int argc, char** argv)
   pthread_t tid[n_threads];
 
   fprintf(stderr, "Start of test.\n");
+  pthread_barrier_init(&s_barrier, 0, 2);
   pthread_create(&tid[0], 0, thread_func_1, 0);
   pthread_create(&tid[1], 0, thread_func_2, 0);
   for (i = 0; i < n_threads; i++)
     pthread_join(tid[i], 0);
+  pthread_barrier_destroy(&s_barrier);
   fprintf(stderr, "Test finished.\n");
 
   return 0;
index ad05687d03ce85f0a9b03bc6e1ee3e7b53903bf0..c974d67ae7fb2482e13eb0c2785ecb66db38de91 100644 (file)
@@ -4,7 +4,7 @@ Conflicting load by thread x at 0x........ size 4
    at 0x........: thread_func_2 (atomic_var.c:?)
    by 0x........: vgDrd_thread_wrapper (drd_pthread_intercepts.c:?)
 Location 0x........ is 0 bytes inside global var "s_y"
-declared at atomic_var.c:35
+declared at atomic_var.c:37
 
 y = 1
 Test finished.
index e764355f900a47eb4f1aedb709b3b41add845c1a..dc74156287ef235f9a572c6b19534089bc302813 100644 (file)
@@ -1,4 +1,4 @@
 prereq: test -e atomic_var && ./supported_libpthread
-vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no --num-callers=2
+vgopts: --fair-sched=yes --read-var-info=yes --check-stack-var=yes --show-confl-seg=no --num-callers=2
 prog: atomic_var
 stderr_filter: filter_stderr_and_thread_no