OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libgomp/] [testsuite/] [libgomp.c++/] [ctor-4.C] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 273 jeremybenn
// { dg-do run }
2
 
3
#include 
4
#include 
5
 
6
struct B
7
{
8
  static int ccount;
9
  static int dcount;
10
  static int ecount;
11
  static B *e_inner;
12
  static B *e_outer;
13
 
14
  B();
15
  B(int);
16
  B(const B &);
17
  ~B();
18
  B& operator=(const B &);
19
  void doit();
20
};
21
 
22
int B::ccount;
23
int B::dcount;
24
int B::ecount;
25
B * B::e_inner;
26
B * B::e_outer;
27
 
28
B::B(int)
29
{
30
  e_outer = this;
31
}
32
 
33
B::B(const B &b)
34
{
35
  assert (&b == e_outer);
36
  #pragma omp atomic
37
    ccount++;
38
}
39
 
40
B::~B()
41
{
42
  #pragma omp atomic
43
    dcount++;
44
}
45
 
46
B& B::operator= (const B &b)
47
{
48
  assert (&b == e_inner);
49
  assert (this == e_outer);
50
  #pragma omp atomic
51
    ecount++;
52
  return *this;
53
}
54
 
55
void B::doit()
56
{
57
  #pragma omp critical
58
    {
59
      assert (e_inner == 0);
60
      e_inner = this;
61
    }
62
}
63
 
64
static int nthreads;
65
 
66
void foo()
67
{
68
  B b(0);
69
 
70
  #pragma omp parallel sections firstprivate(b) lastprivate(b)
71
    {
72
    #pragma omp section
73
      nthreads = omp_get_num_threads ();
74
    #pragma omp section
75
      b.doit ();
76
    }
77
}
78
 
79
int main()
80
{
81
  omp_set_dynamic (0);
82
  omp_set_num_threads (4);
83
  foo();
84
 
85
  assert (B::ecount == 1);
86
  assert (B::ccount == nthreads);
87
  assert (B::dcount == nthreads+1);
88
 
89
  return 0;
90
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.