1 // { dg-do run }
2 
3 #include <omp.h>
4 #include <assert.h>
5 
6 struct B
7 {
8   static int ccount;
9   static int dcount;
10   static int xcount;
11   static B *expected;
12 
13   B();
14   B(int);
15   B(const B &);
16   ~B();
17   B& operator=(const B &);
18   void doit();
19 };
20 
21 int B::ccount;
22 int B::dcount;
23 int B::xcount;
24 B * B::expected;
25 
B(int)26 B::B(int)
27 {
28   expected = this;
29 }
30 
B(const B & b)31 B::B(const B &b)
32 {
33   #pragma omp atomic
34     ccount++;
35   assert (&b == expected);
36 }
37 
~B()38 B::~B()
39 {
40   #pragma omp atomic
41     dcount++;
42 }
43 
doit()44 void B::doit()
45 {
46   #pragma omp atomic
47     xcount++;
48   assert (this != expected);
49 }
50 
51 static int nthreads;
52 
foo()53 void foo()
54 {
55   B b(0);
56 
57   #pragma omp parallel firstprivate(b)
58     {
59       #pragma omp master
60 	nthreads = omp_get_num_threads ();
61       b.doit();
62     }
63 }
64 
main()65 int main()
66 {
67   omp_set_dynamic (0);
68   omp_set_num_threads (4);
69   foo();
70 
71   assert (B::xcount == nthreads);
72   assert (B::ccount == nthreads);
73   assert (B::dcount == nthreads+1);
74 
75   return 0;
76 }
77