1 // RUN: %libomp-compile-and-run
3 #include "omp_testsuite.h"
6 * This test will hang if the nowait is not working properly
8 * It relies on a thread skipping to the second sections construct to
9 * release the threads in the first sections construct
11 * Also, since scheduling of sections is implementation defined, it is
12 * necessary to have all four sections in the second sections construct
13 * release the threads since we can't guarantee which section a single thread
19 void wait_for_release_then_increment(int rank
)
21 fprintf(stderr
, "Thread nr %d enters first section"
22 " and waits.\n", rank
);
28 void release_and_increment(int rank
)
30 fprintf(stderr
, "Thread nr %d sets release to 1\n", rank
);
32 #pragma omp flush(release)
37 int test_omp_sections_nowait()
42 #pragma omp parallel num_threads(4)
45 rank
= omp_get_thread_num ();
46 #pragma omp sections nowait
50 wait_for_release_then_increment(rank
);
54 wait_for_release_then_increment(rank
);
58 wait_for_release_then_increment(rank
);
62 fprintf(stderr
, "Thread nr %d enters first sections and goes "
63 "immediately to next sections construct to release.\n", rank
);
68 /* Begin of second sections environment */
73 release_and_increment(rank
);
77 release_and_increment(rank
);
81 release_and_increment(rank
);
85 release_and_increment(rank
);
89 // Check to make sure all eight sections were executed
98 for(i
= 0; i
< REPETITIONS
; i
++) {
99 if(!test_omp_sections_nowait()) {