2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / ctor-2.C
blob6611c592fda9a83bcc8d60eae8efdb1694d168c2
1 // { dg-do run }
3 #include <omp.h>
4 #include <assert.h>
6 struct B
8   static int ccount;
9   static int dcount;
10   static int xcount;
11   static B *expected;
13   B();
14   B(int);
15   B(const B &);
16   ~B();
17   B& operator=(const B &);
18   void doit();
21 int B::ccount;
22 int B::dcount;
23 int B::xcount;
24 B * B::expected;
26 B::B(int)
28   expected = this;
31 B::B(const B &b)
33   #pragma omp atomic 
34     ccount++;
35   assert (&b == expected);
38 B::~B()
40   #pragma omp atomic
41     dcount++;
44 void B::doit()
46   #pragma omp atomic
47     xcount++;
48   assert (this != expected);
51 static int nthreads;
53 void foo()
55   B b(0);
57   #pragma omp parallel firstprivate(b)
58     {
59       #pragma omp master
60         nthreads = omp_get_num_threads ();
61       b.doit();
62     }
65 int main()
67   omp_set_dynamic (0);
68   omp_set_num_threads (4);
69   foo();
71   assert (B::xcount == nthreads);
72   assert (B::ccount == nthreads);
73   assert (B::dcount == nthreads+1);
75   return 0;