]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgomp/testsuite/libgomp.c/single-1.c
[multiple changes]
[thirdparty/gcc.git] / libgomp / testsuite / libgomp.c / single-1.c
1 /* Trivial test of single. */
2
3 #include <omp.h>
4 #include <sys/time.h>
5 #include <unistd.h>
6 #include <assert.h>
7 #include "libgomp_g.h"
8
9
10 static int test;
11
12 static void f_nocopy (void *dummy)
13 {
14 if (GOMP_single_start ())
15 {
16 int iam = omp_get_thread_num ();
17 int old = __sync_lock_test_and_set (&test, iam);
18 assert (old == -1);
19 }
20 }
21
22 static void f_copy (void *dummy)
23 {
24 int *x = GOMP_single_copy_start ();
25 if (x == NULL)
26 {
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);
31 }
32 else
33 assert (x == &test);
34 }
35
36 int main()
37 {
38 omp_set_dynamic (0);
39
40 test = -1;
41 GOMP_parallel_start (f_nocopy, NULL, 3);
42 f_nocopy (NULL);
43 GOMP_parallel_end ();
44
45 test = -1;
46 GOMP_parallel_start (f_copy, NULL, 3);
47 f_copy (NULL);
48 GOMP_parallel_end ();
49
50 return 0;
51 }