1 /* { dg-do run } */ 2 /* { dg-set-target-env-var OMP_CANCELLATION "true" } */ 3 4 #include <stdlib.h> 5 #include <unistd.h> 6 #include <omp.h> 7 8 static void foo(int * x)9foo (int *x) 10 { 11 #pragma omp parallel firstprivate(x) num_threads (32) 12 { 13 int thr = omp_get_thread_num (); 14 switch (x[thr]) 15 { 16 case 4:; 17 #pragma omp cancel parallel 18 break; 19 case 3: 20 #pragma omp task 21 usleep (1000); 22 #pragma omp task 23 usleep (2000); 24 #pragma omp task 25 usleep (4000); 26 break; 27 case 2: 28 usleep (1000); 29 /* FALLTHRU */ 30 case 1:; 31 #pragma omp cancellation point parallel 32 break; 33 } 34 #pragma omp barrier 35 if (omp_get_cancellation ()) 36 abort (); 37 } 38 } 39 40 int main()41main () 42 { 43 int i, j, x[32] = { 0, 1, 2, 4, 2, 2, 1, 0 }; 44 foo (x); 45 for (i = 0; i < 32; i++) 46 { 47 for (j = 0; j < 32; j++) 48 x[j] = rand () & 3; 49 x[rand () & 31] = 4; 50 foo (x); 51 } 52 return 0; 53 } 54