testsuite/libgomp.c/appendix-a/a.2.1.c

Go to the documentation of this file.
00001 /* { dg-do run } */
00002 
00003 #include <stdio.h>
00004 #include <omp.h>
00005 extern void abort (void);
00006 int
00007 main ()
00008 {
00009   int bad, x;
00010   x = 2;
00011   bad = 0;
00012 #pragma omp parallel num_threads(2) shared(x, bad)
00013   {
00014     if (omp_get_thread_num () == 0)
00015       {
00016     volatile int i;
00017     for (i = 0; i < 100000000; i++)
00018       x = 5;
00019       }
00020     else
00021       {
00022     /* Print 1: the following read of x has a race */
00023     if (x != 2 && x != 5)
00024       bad = 1;
00025       }
00026 #pragma omp barrier
00027     if (omp_get_thread_num () == 0)
00028       {
00029     /* x must be 5 now.  */
00030     if (x != 5)
00031       bad = 1;
00032       }
00033     else
00034       {
00035     /* x must be 5 now.  */
00036     if (x != 5)
00037       bad = 1;
00038       }
00039   }
00040 
00041   if (bad)
00042     abort ();
00043 
00044   return 0;
00045 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7