comparison libgomp/testsuite/libgomp.c/appendix-a/a.2.1.c @ 0:a06113de4d67

first commit
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2009 14:47:48 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a06113de4d67
1 /* { dg-do run } */
2
3 #include <stdio.h>
4 #include <omp.h>
5 extern void abort (void);
6 int
7 main ()
8 {
9 int bad, x;
10 x = 2;
11 bad = 0;
12 #pragma omp parallel num_threads(2) shared(x, bad)
13 {
14 if (omp_get_thread_num () == 0)
15 {
16 volatile int i;
17 for (i = 0; i < 100000000; i++)
18 x = 5;
19 }
20 else
21 {
22 /* Print 1: the following read of x has a race */
23 if (x != 2 && x != 5)
24 bad = 1;
25 }
26 #pragma omp barrier
27 if (omp_get_thread_num () == 0)
28 {
29 /* x must be 5 now. */
30 if (x != 5)
31 bad = 1;
32 }
33 else
34 {
35 /* x must be 5 now. */
36 if (x != 5)
37 bad = 1;
38 }
39 }
40
41 if (bad)
42 abort ();
43
44 return 0;
45 }