1  /* { dg-do run { target *-*-linux* *-*-gnu* *-*-freebsd* } } */
       2  
       3  #ifndef _GNU_SOURCE
       4  #define _GNU_SOURCE 1
       5  #endif
       6  #include <pthread.h>
       7  #include <omp.h>
       8  #include <stdio.h>
       9  #include <stdlib.h>
      10  
      11  pthread_barrier_t bar;
      12  omp_nest_lock_t lock;
      13  
      14  void *tf (void *p)
      15  {
      16    int l;
      17    if (p)
      18      {
      19        if (omp_test_nest_lock (&lock) != 1)
      20  	abort ();
      21        if (omp_test_nest_lock (&lock) != 2)
      22  	abort ();
      23      }
      24    pthread_barrier_wait (&bar);
      25    if (!p && omp_test_nest_lock (&lock) != 0)
      26      abort ();
      27    pthread_barrier_wait (&bar);
      28    if (p)
      29      {
      30        if (omp_test_nest_lock (&lock) != 3)
      31  	abort ();
      32        omp_unset_nest_lock (&lock);
      33        omp_unset_nest_lock (&lock);
      34        omp_unset_nest_lock (&lock);
      35      }
      36    pthread_barrier_wait (&bar);
      37    if (!p)
      38      {
      39        if (omp_test_nest_lock (&lock) != 1)
      40  	abort ();
      41        if (omp_test_nest_lock (&lock) != 2)
      42  	abort ();
      43        omp_unset_nest_lock (&lock);
      44        omp_unset_nest_lock (&lock);
      45      }
      46    return NULL;
      47  }
      48  
      49  int
      50  main (void)
      51  {
      52    pthread_t th;
      53    omp_init_nest_lock (&lock);
      54    pthread_barrier_init (&bar, NULL, 2);
      55    pthread_create (&th, NULL, tf, NULL);
      56    tf ("");
      57    pthread_join (th, NULL);
      58    omp_destroy_nest_lock (&lock);
      59    return 0;
      60  }