summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/ctor-6.C
blob: eab74e08922473be70c39a785cb755720fbbac8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// { dg-do run }

#include <omp.h>
#include <assert.h>

struct B
{
  static int count;
  static B *expected;

  B& operator=(const B &);
};

int B::count;
B * B::expected;

B& B::operator= (const B &b)
{
  assert (&b == expected);
  assert (this != expected);
  #pragma omp atomic
    count++;
  return *this;
}

static int nthreads;

void foo()
{
  #pragma omp parallel
    {
      B b;
      #pragma omp single copyprivate(b)
	{
	  nthreads = omp_get_num_threads ();
	  B::expected = &b;
	}
    }
}

int main()
{
  omp_set_dynamic (0);
  omp_set_num_threads (4);
  foo();

  assert (B::count == nthreads-1);

  return 0;
}