1/* { dg-do run } */
2
3#include <stdio.h>
4#include <omp.h>
5extern void abort (void);
6int
7main ()
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}
46