On Tue, Jun 18, 2013 at 06:15:56PM +0900, Kohji Okuno wrote:
> Hi,
> 
> This is newer document.
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_05_02
> 
> > Hi,
> > 
> > I have a question.
> > 
> > Are pthread_setcancelstate() and pthread_setcanceltype() cancellation
> > points?
> > 
> > I refered to the following URL.
> > 
> > http://pubs.opengroup.org/onlinepubs/7908799/xsh/threads.html
> > 
> > This document shows that cancellation points in the pthread library
> > are only pthread_cond_timedwait(), pthread_cond_wait(), pthread_join()
> > and pthread_testcancel().
> > 
> > But, current implementation in FreeBSD is the following.
> > (Please take notice of "(*)" marks).
> > 
> > Would you check this?
The reason for the testcancel() calls there is that async cancellation
is defined as to be acted upon at any time after the cancellation is
enabled.  If we have pending cancellation request, the async cancellation
must proceed after the pthread_setcancelstate(PTHREAD_CANCEL_ENABLE).

I see a bug there, namely, we should not process the cancellation if
the type is deferred.  Is this is real issue you are concerned with ?

diff --git a/lib/libthr/thread/thr_cancel.c b/lib/libthr/thread/thr_cancel.c
index 89f0ee1..beae707 100644
--- a/lib/libthr/thread/thr_cancel.c
+++ b/lib/libthr/thread/thr_cancel.c
@@ -87,7 +87,8 @@ _pthread_setcancelstate(int state, int *oldstate)
                break;
        case PTHREAD_CANCEL_ENABLE:
                curthread->cancel_enable = 1;
-               testcancel(curthread);
+               if (curthread->cancel_async)
+                       testcancel(curthread);
                break;
        default:
                return (EINVAL);

Attachment: pgpqSTEWOWHFU.pgp
Description: PGP signature

Reply via email to