blob: c5120552702fefd657bca6f1d5be70f85c6e2e63 [file] [log] [blame]
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00001// RUN: %libomp-compile-and-run
Jonathan Peytonac7ba402016-06-28 19:37:24 +00002// RUN: env KMP_LOCK_KIND=tas %libomp-run
3// RUN: env KMP_LOCK_KIND=futex %libomp-run
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00004#include <stdio.h>
5#include "omp_testsuite.h"
6
7omp_lock_t lck;
8
9int test_omp_test_lock()
10{
11 int nr_threads_in_single = 0;
12 int result = 0;
13 int nr_iterations = 0;
14 int i;
15
16 omp_init_lock (&lck);
Jonathan Peyton37310762016-05-17 21:08:52 +000017 #pragma omp parallel shared(lck)
Jonathan Peyton614c7ef2015-09-21 20:41:31 +000018 {
19 #pragma omp for
20 for (i = 0; i < LOOPCOUNT; i++) {
21 while (!omp_test_lock (&lck))
22 {};
23 #pragma omp flush
24 nr_threads_in_single++;
Jonathan Peyton37310762016-05-17 21:08:52 +000025 #pragma omp flush
Jonathan Peyton614c7ef2015-09-21 20:41:31 +000026 nr_iterations++;
27 nr_threads_in_single--;
28 result = result + nr_threads_in_single;
29 omp_unset_lock (&lck);
30 }
31 }
32 omp_destroy_lock(&lck);
33 return ((result == 0) && (nr_iterations == LOOPCOUNT));
34}
35
36int main()
37{
38 int i;
39 int num_failed=0;
40
41 for(i = 0; i < REPETITIONS; i++) {
42 if(!test_omp_test_lock()) {
43 num_failed++;
44 }
45 }
46 return num_failed;
47}