1 // { dg-do run }
2 // { dg-set-target-env-var OMP_CANCELLATION "true" }
3 
4 #include <omp.h>
5 #include <unistd.h>
6 #include "cancel-test.h"
7 
8 static inline void
do_some_work(void)9 do_some_work (void)
10 {
11   asm volatile ("" : : : "memory");
12 }
13 
14 void
foo()15 foo ()
16 {
17   S a, b, c;
18   omp_set_dynamic (0);
19   omp_set_schedule (omp_sched_static, 1);
20   #pragma omp parallel num_threads (16) private (b) firstprivate (c)
21   {
22     S d;
23     int i, j;
24     b.bump ();
25     c.bump ();
26     do_some_work ();
27     #pragma omp barrier
28     if (omp_get_thread_num () == 1)
29       {
30 	sleep (2);
31 	#pragma omp cancellation point parallel
32       }
33     for (j = 3; j <= 16; j++)
34       #pragma omp for schedule (runtime) nowait
35       for (i = 0; i < j; i++)
36 	do_some_work ();
37     if (omp_get_thread_num () == 0)
38       {
39 	sleep (1);
40 	#pragma omp cancel parallel
41       }
42   }
43 }
44 
45 int
main()46 main ()
47 {
48   foo ();
49   S::verify ();
50 }
51