single-1.c 947 B

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