comparison libgomp/testsuite/libgomp.c/appendix-a/a.40.1.c @ 0:a06113de4d67

first commit
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2009 14:47:48 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a06113de4d67
1 /* { dg-do compile } */
2
3 #include <omp.h>
4 typedef struct
5 {
6 int a, b;
7 omp_nest_lock_t lck;
8 } pair;
9 int work1 ();
10 int work2 ();
11 int work3 ();
12 void
13 incr_a (pair * p, int a)
14 {
15 /* Called only from incr_pair, no need to lock. */
16 p->a += a;
17 }
18
19 void
20 incr_b (pair * p, int b)
21 {
22 /* Called both from incr_pair and elsewhere, */
23 /* so need a nestable lock. */
24 omp_set_nest_lock (&p->lck);
25 p->b += b;
26 omp_unset_nest_lock (&p->lck);
27 }
28
29 void
30 incr_pair (pair * p, int a, int b)
31 {
32 omp_set_nest_lock (&p->lck);
33 incr_a (p, a);
34 incr_b (p, b);
35 omp_unset_nest_lock (&p->lck);
36 }
37
38 void
39 a40 (pair * p)
40 {
41 #pragma omp parallel sections
42 {
43 #pragma omp section
44 incr_pair (p, work1 (), work2 ());
45 #pragma omp section
46 incr_b (p, work3 ());
47 }
48 }