mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-09 23:00:07 +00:00
Update.
2003-02-14 Ulrich Drepper <drepper@redhat.com> * sysdeps/generic/libc-start.c [HAVE_PTR_NTHREADS]: Decrement thread counter and only call __exit_thread if this is not the last thread.
This commit is contained in:
parent
e320ef46a7
commit
472022708e
@ -1,3 +1,8 @@
|
||||
2003-02-14 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* sysdeps/generic/libc-start.c [HAVE_PTR_NTHREADS]: Decrement thread
|
||||
counter and only call __exit_thread if this is not the last thread.
|
||||
|
||||
2003-02-13 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* sysdeps/alpha/dl-machine.h (elf_machine_rela): Add instead of
|
||||
|
@ -1,5 +1,19 @@
|
||||
2003-02-14 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* pthreadP.h: Add declaraction for __nptl_nthreads.
|
||||
* pthread_create.c: Define __nptl_nthreads
|
||||
(start_thread): Increment __nptl_nthreads at beginning. Decrement
|
||||
after thread is done. If Then zero call exit(0).
|
||||
* sysdeps/pthread/pthread-functions.h (struct pthread_functions):
|
||||
Add ptr_nthreads. Define HAVE_PTR_NTHREADS.
|
||||
* init.c (pthread_functions): Initialize ptr_nthreads.
|
||||
* allocatestack.c (nptl_nthreads): Remove definition and all uses.
|
||||
(__reclaim_stacks): Decrement __nptl_nthreads.
|
||||
* sysdeps/pthread/Makefile [$(subdir)==csu] (CFLAGS-libc-start.c):
|
||||
Define.
|
||||
* Makefile (tests): Add tst-basic3.
|
||||
* tst-basic3.c: New file.
|
||||
|
||||
* descr.h: Define CANCELING_BIT and CANCELING_BITMASK. Introduce
|
||||
after CANCELTYPE_BIT, move the other bits up. Update CANCEL_RESTMASK.
|
||||
* init.c (sigcancel_handler): Also set CANCELING_BITMASK bit in newval.
|
||||
|
@ -136,7 +136,7 @@ tests = tst-attr1 tst-attr2 \
|
||||
tst-key1 tst-key2 tst-key3 \
|
||||
tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 \
|
||||
tst-barrier1 tst-barrier2 tst-barrier3 \
|
||||
tst-basic1 tst-basic2 \
|
||||
tst-basic1 tst-basic2 tst-basic3 \
|
||||
tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 \
|
||||
tst-tsd1 tst-tsd2 \
|
||||
tst-fork1 tst-fork2 tst-fork3 \
|
||||
|
@ -74,9 +74,6 @@ static LIST_HEAD (stack_used);
|
||||
list_t __stack_user __attribute__ ((nocommon));
|
||||
hidden_def (__stack_user)
|
||||
|
||||
/* Number of threads running. */
|
||||
static unsigned int nptl_nthreads = 1;
|
||||
|
||||
/* Number of threads created. */
|
||||
static unsigned int nptl_ncreated;
|
||||
|
||||
@ -142,9 +139,6 @@ get_cached_stack (size_t *sizep, void **memp)
|
||||
/* And add to the list of stacks in use. */
|
||||
list_add (&result->header.data.list, &stack_used);
|
||||
|
||||
/* One more thread. */
|
||||
++nptl_nthreads;
|
||||
|
||||
/* And decrease the cache size. */
|
||||
stack_cache_actsize -= result->stackblock_size;
|
||||
|
||||
@ -299,9 +293,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
||||
/* And add to the list of stacks in use. */
|
||||
list_add (&pd->header.data.list, &__stack_user);
|
||||
|
||||
/* One more thread. */
|
||||
++nptl_nthreads;
|
||||
|
||||
lll_unlock (stack_cache_lock);
|
||||
}
|
||||
else
|
||||
@ -416,9 +407,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
||||
/* And add to the list of stacks in use. */
|
||||
list_add (&pd->header.data.list, &stack_used);
|
||||
|
||||
/* One more thread. */
|
||||
++nptl_nthreads;
|
||||
|
||||
lll_unlock (stack_cache_lock);
|
||||
|
||||
|
||||
@ -444,9 +432,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
||||
/* Remove the thread from the list. */
|
||||
list_del (&pd->header.data.list);
|
||||
|
||||
/* The thread is gone. */
|
||||
--nptl_nthreads;
|
||||
|
||||
lll_unlock (stack_cache_lock);
|
||||
|
||||
/* Free the memory regardless of whether the size of the
|
||||
@ -510,9 +495,6 @@ __deallocate_stack (struct pthread *pd)
|
||||
/* Free the memory associated with the ELF TLS. */
|
||||
_dl_deallocate_tls (pd, false);
|
||||
|
||||
/* One less thread. */
|
||||
--nptl_nthreads;
|
||||
|
||||
lll_unlock (stack_cache_lock);
|
||||
}
|
||||
|
||||
@ -563,7 +545,7 @@ __reclaim_stacks (void)
|
||||
list_add (&self->header.data.list, &stack_used);
|
||||
|
||||
/* There is one thread running. */
|
||||
nptl_nthreads = 1;
|
||||
__nptl_nthreads = 1;
|
||||
|
||||
/* Initialize the lock. */
|
||||
stack_cache_lock = LLL_LOCK_INITIALIZER;
|
||||
|
@ -110,7 +110,8 @@ static struct pthread_functions pthread_functions =
|
||||
.ptr___pthread_getspecific = __pthread_getspecific_internal,
|
||||
.ptr___pthread_setspecific = __pthread_setspecific_internal,
|
||||
.ptr__pthread_cleanup_push_defer = __pthread_cleanup_push_defer,
|
||||
.ptr__pthread_cleanup_pop_restore = __pthread_cleanup_pop_restore
|
||||
.ptr__pthread_cleanup_pop_restore = __pthread_cleanup_pop_restore,
|
||||
.ptr_nthreads = &__nptl_nthreads
|
||||
};
|
||||
# define ptr_pthread_functions &pthread_functions
|
||||
#else
|
||||
|
@ -61,6 +61,9 @@ extern int __concurrency_level attribute_hidden;
|
||||
extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX];
|
||||
hidden_proto (__pthread_keys)
|
||||
|
||||
/* Number of threads running. */
|
||||
extern unsigned int __nptl_nthreads attribute_hidden;
|
||||
|
||||
/* The library can run in debugging mode where it performs a lot more
|
||||
tests. */
|
||||
extern int __pthread_debug attribute_hidden;
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -17,6 +17,10 @@
|
||||
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
# 02111-1307 USA.
|
||||
|
||||
ifeq ($(subdir),csu)
|
||||
CFLAGS-libc-start.c += -I../nptl
|
||||
endif
|
||||
|
||||
ifeq ($(subdir),nptl)
|
||||
libpthread-sysdep_routines += errno-loc
|
||||
endif
|
||||
|
@ -83,6 +83,8 @@ struct pthread_functions
|
||||
void (*) (void *), void *);
|
||||
void (*ptr__pthread_cleanup_pop_restore) (struct _pthread_cleanup_buffer *,
|
||||
int);
|
||||
#define HAVE_PTR_NTHREADS
|
||||
int *ptr_nthreads;
|
||||
};
|
||||
|
||||
/* Variable in libc.so. */
|
||||
|
87
nptl/tst-basic3.c
Normal file
87
nptl/tst-basic3.c
Normal file
@ -0,0 +1,87 @@
|
||||
/* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
static int nrunning = 1;
|
||||
|
||||
|
||||
static void
|
||||
final_test (void)
|
||||
{
|
||||
puts ("final_test has been called");
|
||||
|
||||
#define THE_SIGNAL SIGUSR1
|
||||
kill (getpid (), SIGUSR1);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
tf (void *a)
|
||||
{
|
||||
if (pthread_join ((pthread_t) a, NULL) != 0)
|
||||
{
|
||||
printf ("join failed while %d are running\n", nrunning);
|
||||
_exit (1);
|
||||
}
|
||||
|
||||
printf ("%2d left\n", --nrunning);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
do_test (void)
|
||||
{
|
||||
#define N 20
|
||||
pthread_t t[N];
|
||||
pthread_t last = pthread_self ();
|
||||
int i;
|
||||
|
||||
atexit (final_test);
|
||||
|
||||
printf ("starting %d + 1 threads\n", N);
|
||||
for (i = 0; i < N; ++i)
|
||||
{
|
||||
if (pthread_create (&t[i], NULL, tf, (void *) last) != 0)
|
||||
{
|
||||
puts ("create failed");
|
||||
_exit (1);
|
||||
}
|
||||
|
||||
++nrunning;
|
||||
|
||||
last = t[i];
|
||||
}
|
||||
|
||||
printf ("%2d left\n", --nrunning);
|
||||
|
||||
pthread_exit (NULL);
|
||||
}
|
||||
|
||||
|
||||
#define EXPECTED_SIGNAL THE_SIGNAL
|
||||
#define TEST_FUNCTION do_test ()
|
||||
#include "../test-skeleton.c"
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
@ -38,6 +38,11 @@ extern void __pthread_initialize_minimal (void)
|
||||
;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PTR_NTHREADS
|
||||
/* We need atomic operations. */
|
||||
# include <atomic.h>
|
||||
#endif
|
||||
|
||||
|
||||
extern int BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
|
||||
int argc,
|
||||
@ -148,8 +153,24 @@ BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
|
||||
}
|
||||
#ifdef HAVE_CANCELBUF
|
||||
else
|
||||
{
|
||||
# ifdef HAVE_PTR_NTHREADS
|
||||
/* One less thread. Decrement the counter. If it is zero we
|
||||
terminate the entire process. */
|
||||
result = 0;
|
||||
int *const ptr;
|
||||
# ifdef SHARED
|
||||
ptr = __libc_pthread_functions.ptr_nthreads;
|
||||
# else
|
||||
extern int __nptl_nthreads __attribute ((weak));
|
||||
ptr = &__nptl_nthreads;
|
||||
# endif
|
||||
|
||||
if (! atomic_decrement_and_test (ptr))
|
||||
# endif
|
||||
/* Not much left to do but to exit the thread, not the process. */
|
||||
__exit_thread (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
exit (result);
|
||||
|
Loading…
Reference in New Issue
Block a user