diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 72ecda8b63..3f017f1e26 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -439,13 +439,6 @@ start_thread (void *arg) /* Clean up any state libc stored in thread-local variables. */ __libc_thread_freeres (); - /* If this is the last thread we terminate the process now. We - do not notify the debugger, it might just irritate it if there - is no thread left. */ - if (__glibc_unlikely (atomic_decrement_and_test (&__nptl_nthreads))) - /* This was the last thread. */ - exit (0); - /* Report the death of the thread if this is wanted. */ if (__glibc_unlikely (pd->report_events)) { @@ -480,6 +473,10 @@ start_thread (void *arg) the breakpoint reports TD_THR_RUN state rather than TD_THR_ZOMBIE. */ atomic_bit_set (&pd->cancelhandling, EXITING_BIT); + if (__glibc_unlikely (atomic_decrement_and_test (&__nptl_nthreads))) + /* This was the last thread. */ + exit (0); + #ifndef __ASSUME_SET_ROBUST_LIST /* If this thread has any robust mutexes locked, handle them now. */ # if __PTHREAD_MUTEX_HAVE_PREV