(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
task-detach-7.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.  Each thread uses
       8     taskwait to wait for the child tasks to complete.  */
       9  
      10  int main (void)
      11  {
      12    int x = 0, y = 0, z = 0;
      13    int thread_count;
      14    omp_event_handle_t detach_event1, detach_event2;
      15  
      16    #pragma omp parallel private (detach_event1, detach_event2)
      17    {
      18      #pragma omp single
      19        thread_count = omp_get_num_threads ();
      20  
      21      #pragma omp task detach (detach_event1) untied
      22        #pragma omp atomic update
      23  	x++;
      24  
      25      #pragma omp task detach (detach_event2) untied
      26      {
      27        #pragma omp atomic update
      28  	y++;
      29        omp_fulfill_event (detach_event1);
      30      }
      31  
      32      #pragma omp task untied
      33      {
      34        #pragma omp atomic update
      35  	z++;
      36        omp_fulfill_event (detach_event2);
      37      }
      38  
      39      #pragma omp taskwait
      40    }
      41  
      42    assert (x == thread_count);
      43    assert (y == thread_count);
      44    assert (z == thread_count);
      45  }