testsuite/libgomp.c++/ctor-5.C

Go to the documentation of this file.
00001 // { dg-do run }
00002 // { dg-require-effective-target tls_runtime }
00003 
00004 #include <omp.h>
00005 #include <assert.h>
00006 
00007 struct B
00008 {
00009   static int count;
00010   static B *expected;
00011 
00012   B& operator=(const B &);
00013 };
00014 
00015 int B::count;
00016 B * B::expected;
00017 
00018 static B thr;
00019 #pragma omp threadprivate(thr)
00020 
00021 B& B::operator= (const B &b)
00022 {
00023   assert (&b == expected);
00024   assert (this != expected);
00025   #pragma omp atomic
00026     count++;
00027   return *this;
00028 }
00029 
00030 static int nthreads;
00031 
00032 void foo()
00033 {
00034   B::expected = &thr;
00035 
00036   #pragma omp parallel copyin(thr)
00037     {
00038     #pragma omp master
00039       nthreads = omp_get_num_threads ();
00040     }
00041 }
00042 
00043 int main()
00044 {
00045   omp_set_dynamic (0);
00046   omp_set_num_threads (4);
00047   foo();
00048 
00049   assert (B::count == nthreads-1);
00050 
00051   return 0;
00052 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7