testsuite/libgomp.c/appendix-a/a.40.1.c

Go to the documentation of this file.
00001 /* { dg-do compile } */
00002 
00003 #include <omp.h>
00004 typedef struct
00005 {
00006   int a, b;
00007   omp_nest_lock_t lck;
00008 } pair;
00009 int work1 ();
00010 int work2 ();
00011 int work3 ();
00012 void
00013 incr_a (pair * p, int a)
00014 {
00015   /* Called only from incr_pair, no need to lock. */
00016   p->a += a;
00017 }
00018 
00019 void
00020 incr_b (pair * p, int b)
00021 {
00022   /* Called both from incr_pair and elsewhere, */
00023   /* so need a nestable lock. */
00024   omp_set_nest_lock (&p->lck);
00025   p->b += b;
00026   omp_unset_nest_lock (&p->lck);
00027 }
00028 
00029 void
00030 incr_pair (pair * p, int a, int b)
00031 {
00032   omp_set_nest_lock (&p->lck);
00033   incr_a (p, a);
00034   incr_b (p, b);
00035   omp_unset_nest_lock (&p->lck);
00036 }
00037 
00038 void
00039 a40 (pair * p)
00040 {
00041 #pragma omp parallel sections
00042   {
00043 #pragma omp section
00044     incr_pair (p, work1 (), work2 ());
00045 #pragma omp section
00046     incr_b (p, work3 ());
00047   }
00048 }

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