2013-06-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgomp / testsuite / libgomp.c / critical-1.c
blob2b8503be7e8fd647b6867438995d15f18ab52aa9
1 /* Trivial test of critical sections. */
3 /* { dg-require-effective-target sync_int_long } */
5 #include <omp.h>
6 #include <sys/time.h>
7 #include <unistd.h>
8 #include <assert.h>
9 #include "libgomp_g.h"
12 static volatile int test = -1;
14 static void function(void *dummy)
16 int iam = omp_get_thread_num ();
17 int old;
19 GOMP_critical_start ();
21 old = __sync_lock_test_and_set (&test, iam);
22 assert (old == -1);
24 usleep (10);
25 test = -1;
27 GOMP_critical_end ();
30 int main()
32 omp_set_dynamic (0);
34 GOMP_parallel_start (function, NULL, 3);
35 function (NULL);
36 GOMP_parallel_end ();
38 return 0;