lock-1.c 731 B

12345678910111213141516171819202122232425262728293031
  1. #include <omp.h>
  2. #include <stdlib.h>
  3. int
  4. main (void)
  5. {
  6. int l = 0;
  7. omp_nest_lock_t lock;
  8. omp_init_nest_lock (&lock);
  9. if (omp_test_nest_lock (&lock) != 1)
  10. abort ();
  11. if (omp_test_nest_lock (&lock) != 2)
  12. abort ();
  13. #pragma omp parallel if (0) reduction (+:l)
  14. {
  15. /* In OpenMP 2.5 this was supposed to return 3,
  16. but in OpenMP 3.0 the parallel region has a different
  17. task and omp_*_lock_t are owned by tasks, not by threads. */
  18. if (omp_test_nest_lock (&lock) != 0)
  19. l++;
  20. }
  21. if (l)
  22. abort ();
  23. if (omp_test_nest_lock (&lock) != 3)
  24. abort ();
  25. omp_unset_nest_lock (&lock);
  26. omp_unset_nest_lock (&lock);
  27. omp_unset_nest_lock (&lock);
  28. omp_destroy_nest_lock (&lock);
  29. return 0;
  30. }