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

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

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