aboutsummaryrefslogtreecommitdiff
path: root/nptl/tst-once4.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-07-01 03:29:50 +0000
committerUlrich Drepper <drepper@redhat.com>2003-07-01 03:29:50 +0000
commit3a4d1e1e490a8c98ad8478973936880c3f4af0bd (patch)
tree0e8a6da9a3d088f573ec96d289b92c23f8683841 /nptl/tst-once4.c
parent5a8e918dc6809872537f589976cc5b9e9d89131c (diff)
downloadglibc-3a4d1e1e490a8c98ad8478973936880c3f4af0bd.tar
glibc-3a4d1e1e490a8c98ad8478973936880c3f4af0bd.tar.gz
glibc-3a4d1e1e490a8c98ad8478973936880c3f4af0bd.tar.bz2
glibc-3a4d1e1e490a8c98ad8478973936880c3f4af0bd.zip
Update.
2003-06-30 Ulrich Drepper <drepper@redhat.com> * sysdeps/unix/sysv/linux/i386/pthread_once.S (__pthread_once): Use correct cleanup handler registration. Add unwind info. * tst-once3.c: Add cleanup handler and check it is called. * tst-once4.c: Likewise. * tst-oncex3.c: New file. * tst-oncex4.c: New file. * Makefile: Add rules to build and run tst-oncex3 and tst-oncex4.
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;