From owner-freebsd-hackers Tue Dec 4 0:18:31 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from elvis.mu.org (elvis.mu.org [216.33.66.196]) by hub.freebsd.org (Postfix) with ESMTP id 6597D37B417; Tue, 4 Dec 2001 00:18:21 -0800 (PST) Received: by elvis.mu.org (Postfix, from userid 1192) id E1B3481D03; Tue, 4 Dec 2001 02:18:15 -0600 (CST) Date: Tue, 4 Dec 2001 02:18:15 -0600 From: Alfred Perlstein To: Daniel Eischen Cc: Louis-Philippe Gagnon , freebsd-current@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG Subject: Re: Possible libc_r pthread bug Message-ID: <20011204021815.E92148@elvis.mu.org> References: <094601c179ea$7cca85c0$2964a8c0@MACADAMIAN.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from eischen@pcnet1.pcnet.com on Fri, Nov 30, 2001 at 05:15:50PM -0500 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG * Daniel Eischen [011130 16:17] wrote: > On Fri, 30 Nov 2001, Louis-Philippe Gagnon wrote: > > If at first you don't succeed... > > > > I've encountered a problem using pthread_cancel, pthread_join and > > pthread_setcanceltype, I'm hoping someone can shed some light. > > > > (in a nutshell : pthread_setcanceltype doesn't seem to work in FreeBSD 4.4) > > > > (posted to -current and -hackers; if there's a more appropriate mailing list > > for this, please let me know) > > > > I recently encountered a situation where, after calling pthread_cancel to > > cancel a thread, the call to pthread_join hangs indefinitely. I quickly figured > > out that it was because the thread being cancelled was never reaching a > > cancellation point (in fact it was an infinite loop with no function calls at all). > > Sure enough, adding a pthread_testcancel() in the loop allowed > > pthread_join to return. However this solution isn't acceptable for my requirements. please test the following patch: Index: uthread/uthread_kern.c =================================================================== RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_kern.c,v retrieving revision 1.39 diff -u -r1.39 uthread_kern.c --- uthread/uthread_kern.c 7 Oct 2001 02:34:43 -0000 1.39 +++ uthread/uthread_kern.c 4 Dec 2001 08:22:22 -0000 @@ -579,6 +579,18 @@ curthread); } /* + * If the currently running thread is a user thread, + * test for async cancel: + */ + if ((curthread->flags & PTHREAD_FLAGS_PRIVATE) == 0) { + int cfl = curthread->cancelflags; + + cfl &= (PTHREAD_CANCEL_ASYNCHRONOUS| + PTHREAD_AT_CANCEL_POINT); + if (cfl != 0) + pthread_testcancel(); + } + /* * Continue the thread at its current frame: */ switch(curthread->ctxtype) { @@ -1078,6 +1090,8 @@ curthread->sig_defer_count--; } else if (curthread->sig_defer_count == 1) { + int cfl; + /* Reenable signals: */ curthread->sig_defer_count = 0; @@ -1091,8 +1105,9 @@ * Check for asynchronous cancellation before delivering any * pending signals: */ - if (((curthread->cancelflags & PTHREAD_AT_CANCEL_POINT) == 0) && - ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0)) + cfl = curthread->cancelflags; + cfl &= (PTHREAD_CANCEL_ASYNCHRONOUS|PTHREAD_AT_CANCEL_POINT); + if (cfl != 0) pthread_testcancel(); /* -- -Alfred Perlstein [alfred@freebsd.org] 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.' http://www.morons.org/rants/gpl-harmful.php3 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message