Re: Are pthread_setcancelstate() and pthread_setcanceltype() cancellation points?

From: Kohji Okuno <okuno.kohji_at_jp.panasonic.com>
Date: Tue, 18 Jun 2013 18:15:56 +0900 (JST)
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?
> 
> 
> lib/libthr/thread/thr_cancel.c:
> 77	int
> 78	_pthread_setcancelstate(int state, int *oldstate)
> 79	{
> 80	        struct pthread *curthread = _get_curthread();
> 81	        int oldval;
> 82	
> 83	        oldval = curthread->cancel_enable;
> 84	        switch (state) {
> 85	        case PTHREAD_CANCEL_DISABLE:
> 86	                curthread->cancel_enable = 0;
> 87	                break;
> 88	        case PTHREAD_CANCEL_ENABLE:
> 89	                curthread->cancel_enable = 1;
> 90 (*)	                testcancel(curthread);
> 91	                break;
> 92	        default:
> 93	                return (EINVAL);
> 94	        }
> 95	
> 96	        if (oldstate) {
> 97	                *oldstate = oldval ? PTHREAD_CANCEL_ENABLE :
> 98	                        PTHREAD_CANCEL_DISABLE;
> 99	        }
> 100	        return (0);
> 101	}
> 102	
> 103	int
> 104	_pthread_setcanceltype(int type, int *oldtype)
> 105	{
> 106	        struct pthread  *curthread = _get_curthread();
> 107	        int oldval;
> 108	
> 109	        oldval = curthread->cancel_async;
> 110	        switch (type) {
> 111	        case PTHREAD_CANCEL_ASYNCHRONOUS:
> 112	                curthread->cancel_async = 1;
> 113 (*)	                testcancel(curthread);
> 114	                break;
> 115	        case PTHREAD_CANCEL_DEFERRED:
> 116	                curthread->cancel_async = 0;
> 117	                break;
> 118	        default:
> 119	                return (EINVAL);
> 120	        }
> 121	
> 122	        if (oldtype) {
> 123	                *oldtype = oldval ? PTHREAD_CANCEL_ASYNCHRONOUS :
> 124	                        PTHREAD_CANCEL_DEFERRED;
> 125	        }
> 126	        return (0);
> 127	}
> 
> 
> Regards,
>  Kohji Okuno
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
Received on Tue Jun 18 2013 - 07:15:58 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:38 UTC