Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 1 | // RUN: %libomp-compile-and-run |
Jonathan Peyton | 377aa40 | 2016-04-14 16:00:37 +0000 | [diff] [blame^] | 2 | // RUN: %libomp-compile && env KMP_LOCK_KIND=tas KMP_SPIN_BACKOFF_PARAMS=2048,200 %libomp-run |
Jonathan Peyton | 614c7ef | 2015-09-21 20:41:31 +0000 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include "omp_testsuite.h" |
| 5 | |
| 6 | omp_lock_t lck; |
| 7 | |
| 8 | int test_omp_lock() |
| 9 | { |
| 10 | int nr_threads_in_single = 0; |
| 11 | int result = 0; |
| 12 | int nr_iterations = 0; |
| 13 | int i; |
| 14 | |
| 15 | omp_init_lock(&lck); |
| 16 | #pragma omp parallel shared(lck) |
| 17 | { |
| 18 | #pragma omp for |
| 19 | for(i = 0; i < LOOPCOUNT; i++) { |
| 20 | omp_set_lock(&lck); |
| 21 | #pragma omp flush |
| 22 | nr_threads_in_single++; |
| 23 | #pragma omp flush |
| 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 | |
| 32 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); |
| 33 | } |
| 34 | |
| 35 | int main() |
| 36 | { |
| 37 | int i; |
| 38 | int num_failed=0; |
| 39 | |
| 40 | for(i = 0; i < REPETITIONS; i++) { |
| 41 | if(!test_omp_lock()) { |
| 42 | num_failed++; |
| 43 | } |
| 44 | } |
| 45 | return num_failed; |
| 46 | } |