critical-1.c 606 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Trivial test of critical sections. */
  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 volatile int test = -1;
  9. static void function(void *dummy)
  10. {
  11. int iam = omp_get_thread_num ();
  12. int old;
  13. GOMP_critical_start ();
  14. old = __sync_lock_test_and_set (&test, iam);
  15. assert (old == -1);
  16. usleep (10);
  17. test = -1;
  18. GOMP_critical_end ();
  19. }
  20. int main()
  21. {
  22. omp_set_dynamic (0);
  23. GOMP_parallel_start (function, NULL, 3);
  24. function (NULL);
  25. GOMP_parallel_end ();
  26. return 0;
  27. }