ctor-2.C revision 1.1.1.1
1// { dg-do run } 2 3#include <omp.h> 4#include <assert.h> 5 6struct 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 21int B::ccount; 22int B::dcount; 23int B::xcount; 24B * B::expected; 25 26B::B(int) 27{ 28 expected = this; 29} 30 31B::B(const B &b) 32{ 33 #pragma omp atomic 34 ccount++; 35 assert (&b == expected); 36} 37 38B::~B() 39{ 40 #pragma omp atomic 41 dcount++; 42} 43 44void B::doit() 45{ 46 #pragma omp atomic 47 xcount++; 48 assert (this != expected); 49} 50 51static int nthreads; 52 53void 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 65int 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