From ad8bb4d13593dcf41d13a59163245ac2468583ce Mon Sep 17 00:00:00 2001 From: David Bartley Date: Wed, 21 Jan 2009 08:54:14 +0000 Subject: [PATCH] Fix failure handling for thread creation --- nptl/pthread_create.c | 8 ++++++ .../sysv/solaris2/kopensolaris-gnu/createthread.c | 29 +++++++++++----------- .../sysv/solaris2/kopensolaris-gnu/internaltypes.h | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 7368df8676..9844624aca 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -245,6 +245,14 @@ start_thread (void *arg) { struct pthread *pd = (struct pthread *) arg; +#ifdef ATTR_FLAG_CREATE_FAILED + if ((pd->flags & ATTR_FLAG_CREATE_FAILED) && IS_DETACHED (pd)) + { + __free_tcb (pd); + __exit_thread_inline (0); + } +#endif + #if HP_TIMING_AVAIL /* Remember the time when the thread was started. */ hp_timing_t now; diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c index 1f28c6e7aa..19171522ba 100644 --- a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c @@ -98,16 +98,24 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr, errval = EPERM; } - /* Resume thread if requested. */ - if (errval == 0) + if (errval == 0 && !(attr->flags & ATTR_FLAG_SUSPENDED)) { - if (!(attr->flags & ATTR_FLAG_SUSPENDED)) - errval = INLINE_SYSCALL (lwp_continue, 1, pd->tid); + errval = INLINE_SYSCALL (lwp_continue, 1, pd->tid); } + else if (errval != 0) + { + pd->flags |= ATTR_FLAG_CREATE_FAILED; + INLINE_SYSCALL (lwp_continue, 1, pd->tid); + + if (!IS_DETACHED (pd)) + { + int result; + lll_wait_tid (pd->tid); + } - /* Kill the thread if we didn't succeed above. */ - if (errval != 0) - INLINE_SYSCALL (lwp_kill, 2, pd->tid, SIGKILL); + /* Note: if the thread is detached, start_thread will free pd; + otherwise the caller of create_thread will free pd. */ + } } if (errval == 0) @@ -120,13 +128,6 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr, else { atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */ - - /* Failed. If the thread is detached, remove the TCB here since - the caller cannot do this. The caller remembered the thread - as detached and cannot reverify that it is not since it must - not access the thread descriptor again. */ - if (IS_DETACHED (pd)) - __deallocate_stack (pd); } return errval; diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h index 8c291d9dbb..c6ab6ec144 100644 --- a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h @@ -54,6 +54,7 @@ struct pthread_attr #define ATTR_FLAG_DAEMON 0x0080 #define ATTR_FLAG_SUSPENDED 0x0100 #define ATTR_FLAG_THR_CREATE 0x0200 +#define ATTR_FLAG_CREATE_FAILED 0x0400 /* Mutex attribute data structure. */ -- 2.11.0