mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
[BZ #3124]
2006-09-05 Ulrich Drepper <drepper@redhat.com> [BZ #3124] * descr.h (struct pthread): Add parent_cancelhandling. * sysdeps/pthread/createthread.c (create_thread): Pass parent cancelhandling value to child. * pthread_create.c (start_thread): If parent thread was canceled reset the SIGCANCEL mask. * Makefile (tests): Add tst-cancel25. * tst-cancel25.c: New file.
This commit is contained in:
@ -1,3 +1,14 @@
|
|||||||
|
2006-09-05 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
[BZ #3124]
|
||||||
|
* descr.h (struct pthread): Add parent_cancelhandling.
|
||||||
|
* sysdeps/pthread/createthread.c (create_thread): Pass parent
|
||||||
|
cancelhandling value to child.
|
||||||
|
* pthread_create.c (start_thread): If parent thread was canceled
|
||||||
|
reset the SIGCANCEL mask.
|
||||||
|
* Makefile (tests): Add tst-cancel25.
|
||||||
|
* tst-cancel25.c: New file.
|
||||||
|
|
||||||
2006-09-05 Jakub Jelinek <jakub@redhat.com>
|
2006-09-05 Jakub Jelinek <jakub@redhat.com>
|
||||||
Ulrich Drepper <drepper@redhat.com>
|
Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ tests = tst-typesizes \
|
|||||||
tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \
|
tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \
|
||||||
tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
|
tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
|
||||||
tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
|
tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
|
||||||
tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 \
|
tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 tst-cancel25 \
|
||||||
tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
|
tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
|
||||||
tst-flock1 tst-flock2 \
|
tst-flock1 tst-flock2 \
|
||||||
tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
|
tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
|
||||||
|
@ -296,6 +296,10 @@ struct pthread
|
|||||||
/* True if thread must stop at startup time. */
|
/* True if thread must stop at startup time. */
|
||||||
bool stopped_start;
|
bool stopped_start;
|
||||||
|
|
||||||
|
/* The parent's cancel handling at the time of the pthread_create
|
||||||
|
call. This might be needed to undo the effects of a cancellation. */
|
||||||
|
int parent_cancelhandling;
|
||||||
|
|
||||||
/* Lock to synchronize access to the descriptor. */
|
/* Lock to synchronize access to the descriptor. */
|
||||||
lll_lock_t lock;
|
lll_lock_t lock;
|
||||||
|
|
||||||
|
@ -251,6 +251,19 @@ start_thread (void *arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If the parent was running cancellation handlers while creating
|
||||||
|
the thread the new thread inherited the signal mask. Reset the
|
||||||
|
cancellation signal mask. */
|
||||||
|
if (__builtin_expect (pd->parent_cancelhandling & CANCELING_BITMASK, 0))
|
||||||
|
{
|
||||||
|
INTERNAL_SYSCALL_DECL (err);
|
||||||
|
sigset_t mask;
|
||||||
|
__sigemptyset (&mask);
|
||||||
|
__sigaddset (&mask, SIGCANCEL);
|
||||||
|
(void) INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_UNBLOCK, &mask,
|
||||||
|
NULL, _NSIG / 8);
|
||||||
|
}
|
||||||
|
|
||||||
/* This is where the try/finally block should be created. For
|
/* This is where the try/finally block should be created. For
|
||||||
compilers without that support we do use setjmp. */
|
compilers without that support we do use setjmp. */
|
||||||
struct pthread_unwind_buf unwind_buf;
|
struct pthread_unwind_buf unwind_buf;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
|
/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
||||||
|
|
||||||
@ -242,6 +242,7 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr,
|
|||||||
|| (attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0))
|
|| (attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0))
|
||||||
stopped = true;
|
stopped = true;
|
||||||
pd->stopped_start = stopped;
|
pd->stopped_start = stopped;
|
||||||
|
pd->parent_cancelhandling = THREAD_GETMEM (THREAD_SELF, cancelhandling);
|
||||||
|
|
||||||
/* Actually create the thread. */
|
/* Actually create the thread. */
|
||||||
int res = do_clone (pd, attr, clone_flags, start_thread,
|
int res = do_clone (pd, attr, clone_flags, start_thread,
|
||||||
|
171
nptl/tst-cancel25.c
Normal file
171
nptl/tst-cancel25.c
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
#include <pthreadP.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
static pthread_barrier_t b;
|
||||||
|
static pthread_t th2;
|
||||||
|
|
||||||
|
|
||||||
|
static void *
|
||||||
|
tf2 (void *arg)
|
||||||
|
{
|
||||||
|
sigset_t mask;
|
||||||
|
if (pthread_sigmask (SIG_SETMASK, NULL, &mask) != 0)
|
||||||
|
{
|
||||||
|
puts ("pthread_sigmask failed");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (sigismember (&mask, SIGCANCEL))
|
||||||
|
{
|
||||||
|
puts ("SIGCANCEL blocked in new thread");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sync with the main thread so that we do not test anything else. */
|
||||||
|
int e = pthread_barrier_wait (&b);
|
||||||
|
if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
|
{
|
||||||
|
puts ("barrier_wait failed");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* Just a cancelable call. */
|
||||||
|
struct timespec ts = { 10000, 0 };
|
||||||
|
nanosleep (&ts, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
unwhand (void *arg)
|
||||||
|
{
|
||||||
|
if (pthread_create (&th2, NULL, tf2, NULL) != 0)
|
||||||
|
{
|
||||||
|
puts ("unwhand: create failed");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void *
|
||||||
|
tf (void *arg)
|
||||||
|
{
|
||||||
|
pthread_cleanup_push (unwhand, NULL);
|
||||||
|
|
||||||
|
/* Sync with the main thread so that we do not test anything else. */
|
||||||
|
int e = pthread_barrier_wait (&b);
|
||||||
|
if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
|
{
|
||||||
|
puts ("barrier_wait failed");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* Just a cancelable call. */
|
||||||
|
struct timespec ts = { 10000, 0 };
|
||||||
|
nanosleep (&ts, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_cleanup_pop (0);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
if (pthread_barrier_init (&b, NULL, 2) != 0)
|
||||||
|
{
|
||||||
|
puts ("barrier_init failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_t th1;
|
||||||
|
if (pthread_create (&th1, NULL, tf, NULL) != 0)
|
||||||
|
{
|
||||||
|
puts ("create failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int e = pthread_barrier_wait (&b);
|
||||||
|
if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
|
{
|
||||||
|
puts ("barrier_wait failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure tf1 enters nanosleep. */
|
||||||
|
struct timespec ts = { 0, 500000000 };
|
||||||
|
while (nanosleep (&ts, &ts) != 0)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (pthread_cancel (th1) != 0)
|
||||||
|
{
|
||||||
|
puts ("1st cancel failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *res;
|
||||||
|
if (pthread_join (th1, &res) != 0)
|
||||||
|
{
|
||||||
|
puts ("1st join failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (res != PTHREAD_CANCELED)
|
||||||
|
{
|
||||||
|
puts ("1st thread not canceled");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
e = pthread_barrier_wait (&b);
|
||||||
|
if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
|
{
|
||||||
|
puts ("barrier_wait failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure tf2 enters nanosleep. */
|
||||||
|
ts.tv_sec = 0;
|
||||||
|
ts.tv_nsec = 500000000;
|
||||||
|
while (nanosleep (&ts, &ts) != 0)
|
||||||
|
;
|
||||||
|
|
||||||
|
puts ("calling pthread_cancel the second time");
|
||||||
|
if (pthread_cancel (th2) != 0)
|
||||||
|
{
|
||||||
|
puts ("2nd cancel failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
puts ("calling pthread_join the second time");
|
||||||
|
if (pthread_join (th2, &res) != 0)
|
||||||
|
{
|
||||||
|
puts ("2nd join failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (res != PTHREAD_CANCELED)
|
||||||
|
{
|
||||||
|
puts ("2nd thread not canceled");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_barrier_destroy (&b) != 0)
|
||||||
|
{
|
||||||
|
puts ("barrier_destroy failed");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#define TIMEOUT 4
|
||||||
|
#include "../test-skeleton.c"
|
Reference in New Issue
Block a user