1*404b540aSrobert // { dg-do run } 2*404b540aSrobert // { dg-require-effective-target tls_runtime } 3*404b540aSrobert 4*404b540aSrobert #include <omp.h> 5*404b540aSrobert #include <assert.h> 6*404b540aSrobert 7*404b540aSrobert struct B 8*404b540aSrobert { 9*404b540aSrobert static int count; 10*404b540aSrobert static B *expected; 11*404b540aSrobert 12*404b540aSrobert B& operator=(const B &); 13*404b540aSrobert }; 14*404b540aSrobert 15*404b540aSrobert int B::count; 16*404b540aSrobert B * B::expected; 17*404b540aSrobert 18*404b540aSrobert static B thr; 19*404b540aSrobert #pragma omp threadprivate(thr) 20*404b540aSrobert 21*404b540aSrobert B& B::operator= (const B &b) 22*404b540aSrobert { 23*404b540aSrobert assert (&b == expected); 24*404b540aSrobert assert (this != expected); 25*404b540aSrobert #pragma omp atomic 26*404b540aSrobert count++; 27*404b540aSrobert return *this; 28*404b540aSrobert } 29*404b540aSrobert 30*404b540aSrobert static int nthreads; 31*404b540aSrobert foo()32*404b540aSrobertvoid foo() 33*404b540aSrobert { 34*404b540aSrobert B::expected = &thr; 35*404b540aSrobert 36*404b540aSrobert #pragma omp parallel copyin(thr) 37*404b540aSrobert { 38*404b540aSrobert #pragma omp master 39*404b540aSrobert nthreads = omp_get_num_threads (); 40*404b540aSrobert } 41*404b540aSrobert } 42*404b540aSrobert main()43*404b540aSrobertint main() 44*404b540aSrobert { 45*404b540aSrobert omp_set_dynamic (0); 46*404b540aSrobert omp_set_num_threads (4); 47*404b540aSrobert foo(); 48*404b540aSrobert 49*404b540aSrobert assert (B::count == nthreads-1); 50*404b540aSrobert 51*404b540aSrobert return 0; 52*404b540aSrobert } 53