aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.4.3/libgomp/testsuite/libgomp.c/appendix-a/a.39.1.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.4.3/libgomp/testsuite/libgomp.c/appendix-a/a.39.1.c')
-rw-r--r--gcc-4.4.3/libgomp/testsuite/libgomp.c/appendix-a/a.39.1.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/gcc-4.4.3/libgomp/testsuite/libgomp.c/appendix-a/a.39.1.c b/gcc-4.4.3/libgomp/testsuite/libgomp.c/appendix-a/a.39.1.c
new file mode 100644
index 000000000..a129e87fc
--- /dev/null
+++ b/gcc-4.4.3/libgomp/testsuite/libgomp.c/appendix-a/a.39.1.c
@@ -0,0 +1,38 @@
+/* { dg-do run } */
+
+#include <stdio.h>
+#include <omp.h>
+void
+skip (int i)
+{
+}
+
+void
+work (int i)
+{
+}
+int
+main ()
+{
+ omp_lock_t lck;
+ int id;
+ omp_init_lock (&lck);
+#pragma omp parallel shared(lck) private(id)
+ {
+ id = omp_get_thread_num ();
+ omp_set_lock (&lck);
+ /* only one thread at a time can execute this printf */
+ printf ("My thread id is %d.\n", id);
+ omp_unset_lock (&lck);
+ while (!omp_test_lock (&lck))
+ {
+ skip (id); /* we do not yet have the lock,
+ so we must do something else */
+ }
+ work (id); /* we now have the lock
+ and can do the work */
+ omp_unset_lock (&lck);
+ }
+ omp_destroy_lock (&lck);
+ return 0;
+}