2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / ctor-5.C
blobd99a1d4628f737721abc1330420d45582e39d071
1 // { dg-do run }
2 // { dg-require-effective-target tls_runtime }
4 #include <omp.h>
5 #include <assert.h>
7 struct B
9   static int count;
10   static B *expected;
12   B& operator=(const B &);
15 int B::count;
16 B * B::expected;
18 static B thr;
19 #pragma omp threadprivate(thr)
21 B& B::operator= (const B &b)
23   assert (&b == expected);
24   assert (this != expected);
25   #pragma omp atomic
26     count++;
27   return *this;
30 static int nthreads;
32 void foo()
34   B::expected = &thr;
36   #pragma omp parallel copyin(thr)
37     {
38     #pragma omp master
39       nthreads = omp_get_num_threads ();
40     }
43 int main()
45   omp_set_dynamic (0);
46   omp_set_num_threads (4);
47   foo();
49   assert (B::count == nthreads-1);
51   return 0;