(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
task-detach-5.c
       1  /* { dg-do run } */
       2  
       3  #include <omp.h>
       4  #include <assert.h>
       5  
       6  /* Test tasks with detach clause.  Each thread spawns off a chain of tasks,
       7     that can then be executed by any available thread.  */
       8  
       9  int main (void)
      10  {
      11    int x = 0, y = 0, z = 0;
      12    int thread_count;
      13    omp_event_handle_t detach_event1, detach_event2;
      14  
      15    #pragma omp parallel private (detach_event1, detach_event2)
      16    {
      17      #pragma omp single
      18        thread_count = omp_get_num_threads ();
      19  
      20      #pragma omp task detach (detach_event1) untied
      21        #pragma omp atomic update
      22  	x++;
      23  
      24      #pragma omp task detach (detach_event2) untied
      25      {
      26        #pragma omp atomic update
      27  	y++;
      28        omp_fulfill_event (detach_event1);
      29      }
      30  
      31      #pragma omp task untied
      32      {
      33        #pragma omp atomic update
      34  	z++;
      35        omp_fulfill_event (detach_event2);
      36      }
      37    }
      38  
      39    assert (x == thread_count);
      40    assert (y == thread_count);
      41    assert (z == thread_count);
      42  }