Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c / lock-3.c
blobb3c7e074b1edb29efca213456718fc187d9637a6
1 /* { dg-do run { target *-*-linux* *-*-gnu* *-*-freebsd* } } */
3 #ifndef _GNU_SOURCE
4 #define _GNU_SOURCE 1
5 #endif
6 #include <pthread.h>
7 #include <omp.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 pthread_barrier_t bar;
12 omp_nest_lock_t lock;
14 void *tf (void *p)
16 int l;
17 if (p)
19 if (omp_test_nest_lock (&lock) != 1)
20 abort ();
21 if (omp_test_nest_lock (&lock) != 2)
22 abort ();
24 pthread_barrier_wait (&bar);
25 if (!p && omp_test_nest_lock (&lock) != 0)
26 abort ();
27 pthread_barrier_wait (&bar);
28 if (p)
30 if (omp_test_nest_lock (&lock) != 3)
31 abort ();
32 omp_unset_nest_lock (&lock);
33 omp_unset_nest_lock (&lock);
34 omp_unset_nest_lock (&lock);
36 pthread_barrier_wait (&bar);
37 if (!p)
39 if (omp_test_nest_lock (&lock) != 1)
40 abort ();
41 if (omp_test_nest_lock (&lock) != 2)
42 abort ();
43 omp_unset_nest_lock (&lock);
44 omp_unset_nest_lock (&lock);
46 return NULL;
49 int
50 main (void)
52 pthread_t th;
53 omp_init_nest_lock (&lock);
54 pthread_barrier_init (&bar, NULL, 2);
55 pthread_create (&th, NULL, tf, NULL);
56 tf ("");
57 pthread_join (th, NULL);
58 omp_destroy_nest_lock (&lock);
59 return 0;