1  /* { dg-do run } */
       2  
       3  #include <stdio.h>
       4  #include <omp.h>
       5  void
       6  skip (int i)
       7  {
       8  }
       9  
      10  void
      11  work (int i)
      12  {
      13  }
      14  int
      15  main ()
      16  {
      17    omp_lock_t lck;
      18    int id;
      19    omp_init_lock (&lck);
      20  #pragma omp parallel shared(lck) private(id)
      21    {
      22      id = omp_get_thread_num ();
      23      omp_set_lock (&lck);
      24      /* only one thread at a time can execute this printf */
      25      printf ("My thread id is %d.\n", id);
      26      omp_unset_lock (&lck);
      27      while (!omp_test_lock (&lck))
      28        {
      29  	skip (id);		/* we do not yet have the lock,
      30  				   so we must do something else */
      31        }
      32      work (id);			/* we now have the lock
      33  				   and can do the work */
      34      omp_unset_lock (&lck);
      35    }
      36    omp_destroy_lock (&lck);
      37    return 0;
      38  }