1/* Trivial test of single.  */
2
3/* { dg-require-effective-target sync_int_long } */
4
5#include <omp.h>
6#include <sys/time.h>
7#include <unistd.h>
8#include <assert.h>
9#include "libgomp_g.h"
10
11
12static int test;
13
14static void f_nocopy (void *dummy)
15{
16  if (GOMP_single_start ())
17    {
18      int iam = omp_get_thread_num ();
19      int old = __sync_lock_test_and_set (&test, iam);
20      assert (old == -1);
21    }
22}
23
24static void f_copy (void *dummy)
25{
26  int *x = GOMP_single_copy_start ();
27  if (x == NULL)
28    {
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);
33    }
34  else
35    assert (x == &test);
36}
37
38int main()
39{
40  omp_set_dynamic (0);
41
42  test = -1;
43  GOMP_parallel_start (f_nocopy, NULL, 3);
44  f_nocopy (NULL);
45  GOMP_parallel_end ();
46
47  test = -1;
48  GOMP_parallel_start (f_copy, NULL, 3);
49  f_copy (NULL);
50  GOMP_parallel_end ();
51
52  return 0;
53}
54