Merge from mainline
[official-gcc.git] / libgomp / testsuite / libgomp.c / single-1.c
blobd1fd5e2de62b46e298108dbd3e3bf79202dfd4e8
1 /* Trivial test of single. */
3 #include <omp.h>
4 #include <sys/time.h>
5 #include <unistd.h>
6 #include <assert.h>
7 #include "libgomp_g.h"
10 static int test;
12 static void f_nocopy (void *dummy)
14 if (GOMP_single_start ())
16 int iam = omp_get_thread_num ();
17 int old = __sync_lock_test_and_set (&test, iam);
18 assert (old == -1);
22 static void f_copy (void *dummy)
24 int *x = GOMP_single_copy_start ();
25 if (x == NULL)
27 int iam = omp_get_thread_num ();
28 int old = __sync_lock_test_and_set (&test, iam);
29 assert (old == -1);
30 GOMP_single_copy_end (&test);
32 else
33 assert (x == &test);
36 int main()
38 omp_set_dynamic (0);
40 test = -1;
41 GOMP_parallel_start (f_nocopy, NULL, 3);
42 f_nocopy (NULL);
43 GOMP_parallel_end ();
45 test = -1;
46 GOMP_parallel_start (f_copy, NULL, 3);
47 f_copy (NULL);
48 GOMP_parallel_end ();
50 return 0;