Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 1 | // RUN: %libomp-compile-and-run |
| 2 | #include <stdio.h> |
| 3 | #include "omp_testsuite.h" |
| 4 | |
| 5 | omp_lock_t lck; |
| 6 | |
| 7 | int test_omp_test_lock() |
| 8 | { |
| 9 | int nr_threads_in_single = 0; |
| 10 | int result = 0; |
| 11 | int nr_iterations = 0; |
| 12 | int i; |
| 13 | |
| 14 | omp_init_lock (&lck); |
Jonathan Peyton | 3731076 | 2016-05-17 21:08:52 +0000 | [diff] [blame] | 15 | #pragma omp parallel shared(lck) |
Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 16 | { |
| 17 | #pragma omp for |
| 18 | for (i = 0; i < LOOPCOUNT; i++) { |
| 19 | while (!omp_test_lock (&lck)) |
| 20 | {}; |
| 21 | #pragma omp flush |
| 22 | nr_threads_in_single++; |
Jonathan Peyton | 3731076 | 2016-05-17 21:08:52 +0000 | [diff] [blame] | 23 | #pragma omp flush |
Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 24 | nr_iterations++; |
| 25 | nr_threads_in_single--; |
| 26 | result = result + nr_threads_in_single; |
| 27 | omp_unset_lock (&lck); |
| 28 | } |
| 29 | } |
| 30 | omp_destroy_lock(&lck); |
| 31 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); |
| 32 | } |
| 33 | |
| 34 | int main() |
| 35 | { |
| 36 | int i; |
| 37 | int num_failed=0; |
| 38 | |
| 39 | for(i = 0; i < REPETITIONS; i++) { |
| 40 | if(!test_omp_test_lock()) { |
| 41 | num_failed++; |
| 42 | } |
| 43 | } |
| 44 | return num_failed; |
| 45 | } |