diff options
author | David Leonard <d@cvs.openbsd.org> | 1999-11-30 03:16:02 +0000 |
---|---|---|
committer | David Leonard <d@cvs.openbsd.org> | 1999-11-30 03:16:02 +0000 |
commit | 7ac7802bc83c9792cb5fb86994f917a1c0bafe81 (patch) | |
tree | b11a4ff5c7ce41fc4005c956650cc9b718fc7f55 /lib/libc_r/uthread/uthread_fork.c | |
parent | ded7db88cd9e24f6ac64f966ac5eaddd60916563 (diff) |
really remove all other threads when fork()ing. (bug was in removing elements from a list whilest walking it)
Diffstat (limited to 'lib/libc_r/uthread/uthread_fork.c')
-rw-r--r-- | lib/libc_r/uthread/uthread_fork.c | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c index 0e9aef59a20..96e19ead19d 100644 --- a/lib/libc_r/uthread/uthread_fork.c +++ b/lib/libc_r/uthread/uthread_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_fork.c,v 1.7 1999/11/25 07:01:35 d Exp $ */ +/* $OpenBSD: uthread_fork.c,v 1.8 1999/11/30 03:16:01 d Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -46,7 +46,6 @@ fork(void) int i, flags; pid_t ret; pthread_t pthread; - pthread_t pthread_save; /* * Defer signals to protect the scheduling queues from access @@ -113,36 +112,28 @@ fork(void) * Enter a loop to remove all threads other than * the running thread from the thread list: */ - pthread = TAILQ_FIRST(&_thread_list); - while (pthread != NULL) { - /* Save the thread to be freed: */ - pthread_save = pthread; - - /* - * Advance to the next thread before - * destroying the current thread: - */ - pthread = TAILQ_NEXT(pthread, dle); + while ((pthread = TAILQ_FIRST(&_thread_list)) != NULL) { + TAILQ_REMOVE(&_thread_list, pthread, tle); /* Make sure this isn't the running thread: */ - if (pthread_save != _thread_run) { - /* Remove this thread from the list: */ - TAILQ_REMOVE(&_thread_list, - pthread_save, tle); - - if(pthread_save->stack != NULL) - _thread_stack_free(pthread_save->stack); + if (pthread != _thread_run) { + /* XXX should let gc do all this. */ + if(pthread->stack != NULL) + _thread_stack_free(pthread->stack); - if (pthread_save->specific_data != NULL) - free(pthread_save->specific_data); + if (pthread->specific_data != NULL) + free(pthread->specific_data); - if (pthread_save->poll_data.fds != NULL) - free(pthread_save->poll_data.fds); + if (pthread->poll_data.fds != NULL) + free(pthread->poll_data.fds); - free(pthread_save); + free(pthread); } } + /* Restore the running thread */ + TAILQ_INSERT_HEAD(&_thread_list, _thread_run, tle); + /* Re-init the dead thread list: */ TAILQ_INIT(&_dead_list); |