Skip to content

Commit

Permalink
[BZ #530]
Browse files Browse the repository at this point in the history
2004-11-09  Roland McGrath  <roland@redhat.com>
	[BZ #530]
	* sysdeps/pthread/createthread.c (do_clone): Increment __nptl_nthreads
	here, before calling clone.
	* pthread_create.c (start_thread): Don't do it here.
  • Loading branch information
Roland McGrath committed Nov 9, 2004
1 parent d1e0c70 commit fd5d6a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 0 additions & 3 deletions nptl/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ __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
Expand Down
12 changes: 12 additions & 0 deletions nptl/sysdeps/pthread/createthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr,
until we tell it to. */
lll_lock (pd->lock);

/* One more thread. We cannot have the thread do this itself, since it
might exist but not have been scheduled yet by the time we've returned
and need to check the value to behave correctly. We must do it before
creating the thread, in case it does get scheduled first and then
might mistakenly think it was the only thread. In the failure case,
we momentarily store a false value; this doesn't matter because there
is no kosher thing a signal handler interrupting us right here can do
that cares whether the thread count is correct. */
atomic_increment (&__nptl_nthreads);

if (ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags,
pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
{
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
Expand Down

0 comments on commit fd5d6a6

Please sign in to comment.