]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Cleaned up the source code of the atomic_var regression test, without changing the...
authorBart Van Assche <bvanassche@acm.org>
Sun, 15 Feb 2009 10:19:35 +0000 (10:19 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 15 Feb 2009 10:19:35 +0000 (10:19 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9161

drd/tests/atomic_var.c
drd/tests/atomic_var.stderr.exp-with-atomic-builtins-1
drd/tests/atomic_var.stderr.exp-with-atomic-builtins-2

index a4e6ab2f3737068fbc2aa7518d7fbbd1ddb910ec..ebad1ee6c06662968e8420c6447fdb358ad68469 100644 (file)
@@ -1,8 +1,13 @@
-/** Race condition around use of atomic variable.
- *  Note: for the i386 and x86_64 memory models, thread 2 must print y = 1.
- *  On PPC however, both y = 0 and y = 1 are legal results. This is because
- *  the PPC memory model allows different CPU's to observe stores to variables
- *  in different cache lines in a different order.
+/**
+ * This test program triggers a single race condition on variable s_y.
+ * Although another variable (s_x) is also modified by both threads, no race
+ * condition must be reported on this variable since it is only accessed via
+ * atomic instructions.
+ *
+ * Note: for the i386 and x86_64 memory models, thread 2 must print y = 1.
+ * On PPC however, both y = 0 and y = 1 are legal results. This is because
+ * the PPC memory model allows different CPU's to observe stores to variables
+ * in different cache lines in a different order.
  */
 
 
 #include "../../config.h"
 
 
-/** Only gcc 4.1.0 and later have atomic builtins. */
+/* Atomic builtins are only supported by gcc 4.1.0 and later. */
+
 #if defined(HAVE_BUILTIN_ATOMIC)
+
 static __inline__
 int sync_add_and_fetch(int* p, int i)
 {
   return __sync_add_and_fetch(p, i);
 }
-#else
-static __inline__
-int sync_add_and_fetch(int* p, int i)
-{
-  if (i == 0)
-    return *p;
-  return (*p += i);
-}
-#endif
 
-
-#ifdef HAVE_BUILTIN_ATOMIC
 static int s_x = 0;
-/* s_dummy[] ensures that s_x and s_y are not in the same cache line. */
-static char s_dummy[512];
+/* g_dummy[] ensures that s_x and s_y are not in the same cache line. */
+char g_dummy[512];
 static int s_y = 0;
 
 static void* thread_func_1(void* arg)
@@ -52,11 +48,9 @@ static void* thread_func_2(void* arg)
   fprintf(stderr, "y = %d\n", s_y);
   return 0;
 }
-#endif
 
 int main(int argc, char** argv)
 {
-#ifdef HAVE_BUILTIN_ATOMIC
   int i;
   const int n_threads = 2;
   pthread_t tid[n_threads];
@@ -68,13 +62,17 @@ int main(int argc, char** argv)
     pthread_join(tid[i], 0);
   fprintf(stderr, "Test finished.\n");
 
-  /* Suppress the compiler warning about s_dummy not being used. */
-  s_dummy[0]++;
+  return 0;
+}
+
 #else
+
+int main(int argc, char** argv)
+{
   fprintf(stderr,
           "Sorry, but your compiler does not have built-in support for atomic"
           " operations.\n");
-#endif
-
   return 0;
 }
+
+#endif
index 09948055f1897d34f988038102f9bf291127c399..859f3649c88990074f783732a93324ad262d0a97 100644 (file)
@@ -7,7 +7,7 @@ Conflicting load by thread 2/3 at 0x........ size 4
    by 0x........: (within libpthread-?.?.so)
    by 0x........: clone (in /...libc...)
 Location 0x........ is 0 bytes inside local var "s_y"
-declared at atomic_var.c:39, in frame #? of thread 2
+declared at atomic_var.c:35, in frame #? of thread 2
 y = 1
 Test finished.
 
index 2f82e10f87c1ed12f239cc25dd7fe0d4a4113a63..45bf438166f0ee36f77a04e8aaed8dabc2f0189f 100644 (file)
@@ -7,7 +7,7 @@ Conflicting load by thread 3/3 at 0x........ size 4
    by 0x........: (within libpthread-?.?.so)
    by 0x........: clone (in /...libc...)
 Location 0x........ is 0 bytes inside local var "s_y"
-declared at atomic_var.c:39, in frame #? of thread 3
+declared at atomic_var.c:35, in frame #? of thread 3
 y = 1
 Test finished.