diff options
author | jasone <jasone@FreeBSD.org> | 2001-08-16 06:31:32 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2001-08-16 06:31:32 +0000 |
commit | 6e7ccfd0939ba6aaace23d8e2434af0d3dd8ab28 (patch) | |
tree | 58d56e8f03dd7d3a15b34ecf3a5680c7e056fa65 /lib/libpthread/thread/thr_cancel.c | |
parent | cd3f3aab8e337abe90764fb04a24c977624fdecd (diff) | |
download | FreeBSD-src-6e7ccfd0939ba6aaace23d8e2434af0d3dd8ab28.zip FreeBSD-src-6e7ccfd0939ba6aaace23d8e2434af0d3dd8ab28.tar.gz |
Fix a bug in canceling joining threads.
Do not detach canceled threads.
Reported by: Arno Klaassen <arno@heho.snv.jussieu.fr>
Collaboration with: deischen
Diffstat (limited to 'lib/libpthread/thread/thr_cancel.c')
-rw-r--r-- | lib/libpthread/thread/thr_cancel.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libpthread/thread/thr_cancel.c b/lib/libpthread/thread/thr_cancel.c index 2af3db6..7f40e36 100644 --- a/lib/libpthread/thread/thr_cancel.c +++ b/lib/libpthread/thread/thr_cancel.c @@ -64,9 +64,23 @@ _pthread_cancel(pthread_t pthread) 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 @@ -189,7 +203,6 @@ _pthread_testcancel(void) */ curthread->cancelflags &= ~PTHREAD_CANCELLING; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } @@ -226,7 +239,6 @@ finish_cancellation(void *arg) if ((curthread->cancelflags & PTHREAD_CANCEL_NEEDED) != 0) { curthread->cancelflags &= ~PTHREAD_CANCEL_NEEDED; _thread_exit_cleanup(); - pthread_detach((pthread_t)curthread); pthread_exit(PTHREAD_CANCELED); } } |