Merge from mainline
[official-gcc.git] / libgomp / testsuite / libgomp.c / appendix-a / a.39.1.c
bloba129e87fc49f12b0000ecb69ab3126c87b2117cc
1 /* { dg-do run } */
3 #include <stdio.h>
4 #include <omp.h>
5 void
6 skip (int i)
10 void
11 work (int i)
14 int
15 main ()
17 omp_lock_t lck;
18 int id;
19 omp_init_lock (&lck);
20 #pragma omp parallel shared(lck) private(id)
22 id = omp_get_thread_num ();
23 omp_set_lock (&lck);
24 /* only one thread at a time can execute this printf */
25 printf ("My thread id is %d.\n", id);
26 omp_unset_lock (&lck);
27 while (!omp_test_lock (&lck))
29 skip (id); /* we do not yet have the lock,
30 so we must do something else */
32 work (id); /* we now have the lock
33 and can do the work */
34 omp_unset_lock (&lck);
36 omp_destroy_lock (&lck);
37 return 0;