blob: 73802c27e123bf6935dca7cbc68431d4a16dc285 [file] [log] [blame]
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00001// RUN: %libomp-compile-and-run
Jonathan Peyton377aa402016-04-14 16:00:37 +00002// RUN: %libomp-compile && env KMP_LOCK_KIND=tas KMP_SPIN_BACKOFF_PARAMS=2048,200 %libomp-run
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00003#include <stdio.h>
4#include "omp_testsuite.h"
5
6omp_lock_t lck;
7
8int 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
35int 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}