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