Daily bump.
[official-gcc.git] / libgomp / testsuite / libgomp.c / single-1.c
blob1ce89118d813af3094835f06a7d529265a6b1db2
1 /* Trivial test of single. */
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 int test;
14 static void f_nocopy (void *dummy)
16 if (GOMP_single_start ())
18 int iam = omp_get_thread_num ();
19 int old = __sync_lock_test_and_set (&test, iam);
20 assert (old == -1);
24 static void f_copy (void *dummy)
26 int *x = GOMP_single_copy_start ();
27 if (x == NULL)
29 int iam = omp_get_thread_num ();
30 int old = __sync_lock_test_and_set (&test, iam);
31 assert (old == -1);
32 GOMP_single_copy_end (&test);
34 else
35 assert (x == &test);
38 int main()
40 omp_set_dynamic (0);
42 test = -1;
43 GOMP_parallel_start (f_nocopy, NULL, 3);
44 f_nocopy (NULL);
45 GOMP_parallel_end ();
47 test = -1;
48 GOMP_parallel_start (f_copy, NULL, 3);
49 f_copy (NULL);
50 GOMP_parallel_end ();
52 return 0;