2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / ctor-10.C
blobf46e45ec4187032f9d201eba1cc20ba9cfdab1fb
1 // { dg-do run }
2 // { dg-require-effective-target tls_runtime }
4 #include <omp.h>
5 #include <assert.h>
7 #define N 10
8 #define THR 4
10 struct B
12   B();
13   B(const B &);
14   ~B();
15   B& operator=(const B &);
16   void doit();
17   static B *base;
18   static B *threadbase;
19 #pragma omp threadprivate(threadbase)
22 B *B::base;
23 B *B::threadbase;
24 static unsigned cmask[THR];
25 static unsigned dmask[THR];
27 B::B()
29   assert (base == 0);
32 B::B(const B &b)
34   unsigned index = &b - base;
35   assert (index < N);
36   cmask[omp_get_thread_num()] |= 1u << index;
39 B::~B()
41   if (threadbase)
42     {
43       unsigned index = this - threadbase;
44       assert (index < N);
45       dmask[omp_get_thread_num()] |= 1u << index;
46     }
49 void foo()
51   B b[N];
53   B::base = b;
55   #pragma omp parallel firstprivate(b)
56     {
57       assert (omp_get_num_threads () == THR);
58       B::threadbase = b;
59     }
61   B::threadbase = 0;
64 int main()
66   omp_set_dynamic (0);
67   omp_set_num_threads (THR);
68   foo();
70   for (int i = 0; i < THR; ++i)
71     {
72       unsigned xmask = (1u << N) - 1;
73       assert (cmask[i] == xmask);
74       assert (dmask[i] == xmask);
75     }
77   return 0;