1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include "omp_testsuite.h"
4
5omp_nest_lock_t lck;
6
7int test_omp_nest_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_nest_lock(&lck);
15 #pragma omp parallel shared(lck)
16 {
17 #pragma omp for
18 for(i = 0; i < LOOPCOUNT; i++) {
19 omp_set_nest_lock(&lck);
20 #pragma omp flush
21 nr_threads_in_single++;
22 #pragma omp flush
23 nr_iterations++;
24 nr_threads_in_single--;
25 result = result + nr_threads_in_single;
26 omp_unset_nest_lock(&lck);
27 }
28 }
29 omp_destroy_nest_lock(&lck);
30
31 return ((result == 0) && (nr_iterations == LOOPCOUNT));
32}
33
34int main()
35{
36 int i;
37 int num_failed=0;
38
39 for(i = 0; i < REPETITIONS; i++) {
40 if(!test_omp_nest_lock()) {
41 num_failed++;
42 }
43 }
44 return num_failed;
45}
46

source code of openmp/runtime/test/lock/omp_nest_lock.c