about summary refs log tree commit diff
path: root/nptl/tst-once4.c
diff options
context:
space:
mode:
Diffstat (limited to 'nptl/tst-once4.c')
-rw-r--r--nptl/tst-once4.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/nptl/tst-once4.c b/nptl/tst-once4.c
index be83b54692..bf0638b63f 100644
--- a/nptl/tst-once4.c
+++ b/nptl/tst-once4.c
@@ -34,6 +34,7 @@ static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
 static pthread_barrier_t bar;
 
 static int global;
+static int cl_called;
 
 static void
 once_handler1 (void)
@@ -64,11 +65,22 @@ once_handler2 (void)
 }
 
 
+static void
+cl (void *arg)
+{
+  ++cl_called;
+}
+
+
 static void *
 tf1 (void *arg)
 {
+  pthread_cleanup_push (cl, NULL);
+
   pthread_once (&once, once_handler1);
 
+  pthread_cleanup_pop (0);
+
   /* We should never get here.  */
   puts ("pthread_once in tf returned");
   exit (1);
@@ -78,6 +90,8 @@ tf1 (void *arg)
 static void *
 tf2 (void *arg)
 {
+  pthread_cleanup_push (cl, NULL);
+
   int r = pthread_barrier_wait (&bar);
   if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
     {
@@ -85,6 +99,8 @@ tf2 (void *arg)
       exit (1);
     }
 
+  pthread_cleanup_pop (0);
+
   pthread_once (&once, once_handler2);
 
   return NULL;
@@ -99,46 +115,46 @@ do_test (void)
   if (pthread_barrier_init (&bar, NULL, 2) != 0)
     {
       puts ("barrier_init failed");
-      exit (1);
+      return 1;
     }
 
   if (pthread_create (&th[0], NULL, tf1, NULL) != 0)
     {
       puts ("first create failed");
-      exit (1);
+      return 1;
     }
 
   int r = pthread_barrier_wait (&bar);
   if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
     {
       puts ("first barrier_wait failed");
-      exit (1);
+      return 1;
     }
 
   if (pthread_mutex_lock (&mut) != 0)
     {
       puts ("mutex_lock failed");
-      exit (1);
+      return 1;
     }
   /* We unlock the mutex so that we catch the case where the pthread_cond_wait
      call incorrectly resumes and tries to get the mutex.  */
   if (pthread_mutex_unlock (&mut) != 0)
     {
       puts ("mutex_unlock failed");
-      exit (1);
+      return 1;
     }
 
   if (pthread_create (&th[1], NULL, tf2, NULL) != 0)
     {
       puts ("second create failed");
-      exit (1);
+      return 1;
     }
 
   r = pthread_barrier_wait (&bar);
   if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
     {
       puts ("second barrier_wait failed");
-      exit (1);
+      return 1;
     }
 
   /* Give the second thread a chance to reach the pthread_once call.  */
@@ -148,7 +164,7 @@ do_test (void)
   if (pthread_cancel (th[0]) != 0)
     {
       puts ("cancel failed");
-      exit (1);
+      return 1;
     }
 
   void *result;
@@ -156,7 +172,7 @@ do_test (void)
   if (result != PTHREAD_CANCELED)
     {
       puts ("first join didn't return PTHREAD_CANCELED");
-      exit (1);
+      return 1;
     }
 
   puts ("joined first thread");
@@ -165,13 +181,19 @@ do_test (void)
   if (result != NULL)
     {
       puts ("second join didn't return PTHREAD_CANCELED");
-      exit (1);
+      return 1;
     }
 
   if (global != 1)
     {
       puts ("global still 0");
-      exit (1);
+      return 1;
+    }
+
+  if (cl_called != 1)
+    {
+      printf ("cl_called = %d\n", cl_called);
+      return 1;
     }
 
   return 0;