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