Merge C++ from gomp-20050608-branch.
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / ctor-9.C
blob215a901f8d352d94c1f73721199c2e2b3ec82110
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& operator=(const B &);
15 static B *base;
16 static B *threadbase;
17 static int singlethread;
18 #pragma omp threadprivate(threadbase)
20 static unsigned cmask[THR];
22 B& B::operator= (const B &b)
24   unsigned sindex = &b - base;
25   unsigned tindex = this - threadbase;
26   assert(sindex < N);
27   assert(sindex == tindex);
28   cmask[omp_get_thread_num ()] |= 1u << tindex;
29   return *this;
32 void foo()
34   #pragma omp parallel
35     {
36       B b[N];
37       threadbase = b;
38       #pragma omp single copyprivate(b)
39         {
40           assert(omp_get_num_threads () == THR);
41           singlethread = omp_get_thread_num ();
42           base = b;
43         }
44     }
47 int main()
49   omp_set_dynamic (0);
50   omp_set_num_threads (THR);
51   foo();
53   for (int i = 0; i < THR; ++i)
54     if (i == singlethread)
55       assert(cmask[singlethread] == 0);
56     else
57       assert(cmask[i] == (1u << N) - 1);
59   return 0;