diff options
Diffstat (limited to 'nptl/pthread_create.c')
-rw-r--r-- | nptl/pthread_create.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 2b33243cee..c96a2813e5 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -44,6 +44,9 @@ static td_thr_events_t __nptl_threads_events; /* Pointer to descriptor with the last event. */ static struct pthread *__nptl_last_event; +/* Number of threads running. */ +unsigned int __nptl_nthreads = 1; + /* Code to allocate and deallocate a stack. */ #define DEFINE_DEALLOC @@ -197,6 +200,9 @@ __free_tcb (struct pthread *pd) static int start_thread (void *arg) { + /* One more thread. */ + atomic_increment (&__nptl_nthreads); + struct pthread *pd = (struct pthread *) arg; #if HP_TIMING_AVAIL @@ -215,6 +221,14 @@ start_thread (void *arg) } + /* 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 (atomic_decrement_and_test (&__nptl_nthreads)) + /* This was the last thread. */ + exit (0); + + /* Report the death of the thread if this is wanted. */ if (__builtin_expect (pd->report_events, 0)) { |