[Instrumentation] Fix a warning
[llvm-project.git] / openmp / runtime / test / lock / omp_lock.c
blob1301f27c4417f19561fcfc17530e289b011b7532
1 // RUN: %libomp-compile-and-run
2 // RUN: env KMP_LOCK_KIND=tas KMP_SPIN_BACKOFF_PARAMS=2048,200 %libomp-run
3 // RUN: env KMP_LOCK_KIND=futex %libomp-run
4 #include <stdio.h>
5 #include "omp_testsuite.h"
7 omp_lock_t lck;
9 int test_omp_lock()
11 int nr_threads_in_single = 0;
12 int result = 0;
13 int nr_iterations = 0;
14 int i;
16 omp_init_lock(&lck);
17 #pragma omp parallel shared(lck)
19 #pragma omp for
20 for(i = 0; i < LOOPCOUNT; i++) {
21 omp_set_lock(&lck);
22 #pragma omp flush
23 nr_threads_in_single++;
24 #pragma omp flush
25 nr_iterations++;
26 nr_threads_in_single--;
27 result = result + nr_threads_in_single;
28 omp_unset_lock(&lck);
31 omp_destroy_lock(&lck);
33 return ((result == 0) && (nr_iterations == LOOPCOUNT));
36 int main()
38 int i;
39 int num_failed=0;
41 for(i = 0; i < REPETITIONS; i++) {
42 if(!test_omp_lock()) {
43 num_failed++;
46 return num_failed;