Mercurial > hg > CbC > CbC_gcc
comparison libgomp/testsuite/libgomp.c++/ctor-4.C @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
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 ecount; | |
11 static B *e_inner; | |
12 static B *e_outer; | |
13 | |
14 B(); | |
15 B(int); | |
16 B(const B &); | |
17 ~B(); | |
18 B& operator=(const B &); | |
19 void doit(); | |
20 }; | |
21 | |
22 int B::ccount; | |
23 int B::dcount; | |
24 int B::ecount; | |
25 B * B::e_inner; | |
26 B * B::e_outer; | |
27 | |
28 B::B(int) | |
29 { | |
30 e_outer = this; | |
31 } | |
32 | |
33 B::B(const B &b) | |
34 { | |
35 assert (&b == e_outer); | |
36 #pragma omp atomic | |
37 ccount++; | |
38 } | |
39 | |
40 B::~B() | |
41 { | |
42 #pragma omp atomic | |
43 dcount++; | |
44 } | |
45 | |
46 B& B::operator= (const B &b) | |
47 { | |
48 assert (&b == e_inner); | |
49 assert (this == e_outer); | |
50 #pragma omp atomic | |
51 ecount++; | |
52 return *this; | |
53 } | |
54 | |
55 void B::doit() | |
56 { | |
57 #pragma omp critical | |
58 { | |
59 assert (e_inner == 0); | |
60 e_inner = this; | |
61 } | |
62 } | |
63 | |
64 static int nthreads; | |
65 | |
66 void foo() | |
67 { | |
68 B b(0); | |
69 | |
70 #pragma omp parallel sections firstprivate(b) lastprivate(b) | |
71 { | |
72 #pragma omp section | |
73 nthreads = omp_get_num_threads (); | |
74 #pragma omp section | |
75 b.doit (); | |
76 } | |
77 } | |
78 | |
79 int main() | |
80 { | |
81 omp_set_dynamic (0); | |
82 omp_set_num_threads (4); | |
83 foo(); | |
84 | |
85 assert (B::ecount == 1); | |
86 assert (B::ccount == nthreads); | |
87 assert (B::dcount == nthreads+1); | |
88 | |
89 return 0; | |
90 } |