Date: Thu, 12 Jul 2001 14:11:54 -0700 From: Jason Evans <jasone@canonware.com> To: "Arno J. Klaassen" <arno@heho.snv.jussieu.fr> Cc: freebsd-stable@FreeBSD.ORG, Daniel Eischen <eischen@vigrid.com> Subject: Re: Changed behaviour of pthread_join (bug?) Message-ID: <20010712141154.O22464@canonware.com> In-Reply-To: <wpbsmqq93z.fsf@heho.snv.jussieu.fr>; from arno@heho.snv.jussieu.fr on Thu, Jul 12, 2001 at 08:45:52PM %2B0200 References: <wpbsmqq93z.fsf@heho.snv.jussieu.fr>
next in thread | previous in thread | raw e-mail | index | archive | help
--ADZbWkCsHQ7r3kzd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Attached is a patch for -stable that should fix the problem your test exposes, as well as a problem that your actual program might hit (canceled threads should not detach). I also noticed and hopefully fixed a problem with canceling a thread suspended while joining, but you probably don't do that. =) Please give the patch a try and let me know if it works for you. Thanks, Jason P.S. Dan Eischen provided the bulk of this fix. Thanks Dan! --ADZbWkCsHQ7r3kzd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="cancel_join.diff" Index: uthread_cancel.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_cancel.c,v retrieving revision 1.3.2.3 diff -u -r1.3.2.3 uthread_cancel.c --- uthread_cancel.c 2001/06/23 00:47:05 1.3.2.3 +++ uthread_cancel.c 2001/07/12 20:59:13 @@ -59,9 +59,23 @@ break; case PS_JOIN: + /* + * Disconnect the thread from the joinee and + * detach: + */ + if (pthread->data.thread != NULL) { + pthread->data.thread->joiner = NULL; + pthread_detach((pthread_t) + pthread->data.thread); + } + pthread->cancelflags |= PTHREAD_CANCELLING; + PTHREAD_NEW_STATE(pthread, PS_RUNNING); + break; + case PS_SUSPENDED: if (pthread->suspended == SUSP_NO || pthread->suspended == SUSP_YES || + pthread->suspended == SUSP_JOIN || pthread->suspended == SUSP_NOWAIT) { /* * This thread isn't in any scheduling @@ -180,7 +194,6 @@ */ _thread_run->cancelflags &= ~PTHREAD_CANCELLING; _thread_exit_cleanup(); - pthread_detach((pthread_t)_thread_run); pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } @@ -211,7 +224,6 @@ if ((_thread_run->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) { _thread_run->cancelflags &= ~PTHREAD_CANCEL_NEEDED; _thread_exit_cleanup(); - pthread_detach((pthread_t)_thread_run); pthread_exit(PTHREAD_CANCELED); } } Index: uthread_join.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_join.c,v retrieving revision 1.12.2.3 diff -u -r1.12.2.3 uthread_join.c --- uthread_join.c 2001/07/05 16:04:09 1.12.2.3 +++ uthread_join.c 2001/07/12 20:30:29 @@ -119,6 +119,9 @@ /* Set the running thread to be the joiner: */ pthread->joiner = _thread_run; + /* Keep track of which thread we're joining to: */ + _thread_run->data.thread = pthread; + /* Schedule the next thread: */ _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); --ADZbWkCsHQ7r3kzd-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010712141154.O22464>