From owner-freebsd-current@FreeBSD.ORG Tue Jun 18 14:34:38 2013 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id A9994273 for ; Tue, 18 Jun 2013 14:34:38 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 49FD31D8D for ; Tue, 18 Jun 2013 14:34:38 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r5IEYSIh051920; Tue, 18 Jun 2013 17:34:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r5IEYSIh051920 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r5IEYSMT051919; Tue, 18 Jun 2013 17:34:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 18 Jun 2013 17:34:28 +0300 From: Konstantin Belousov To: Kohji Okuno Subject: Re: Are pthread_setcancelstate() and pthread_setcanceltype() cancellation points? Message-ID: <20130618143428.GV91021@kib.kiev.ua> References: <20130618.174849.1772987860003116966.okuno.kohji@jp.panasonic.com> <20130618.181556.452619654831646148.okuno.kohji@jp.panasonic.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Pe/WPRK8yIcEP0xy" Content-Disposition: inline In-Reply-To: <20130618.181556.452619654831646148.okuno.kohji@jp.panasonic.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-current@FreeBSD.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jun 2013 14:34:38 -0000 --Pe/WPRK8yIcEP0xy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 18, 2013 at 06:15:56PM +0900, Kohji Okuno wrote: > Hi, >=20 > This is newer document. >=20 > http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#= tag_15_09_05_02 >=20 > > Hi, > >=20 > > I have a question. > >=20 > > Are pthread_setcancelstate() and pthread_setcanceltype() cancellation > > points? > >=20 > > I refered to the following URL. > >=20 > > http://pubs.opengroup.org/onlinepubs/7908799/xsh/threads.html > >=20 > > This document shows that cancellation points in the pthread library > > are only pthread_cond_timedwait(), pthread_cond_wait(), pthread_join() > > and pthread_testcancel(). > >=20 > > But, current implementation in FreeBSD is the following. > > (Please take notice of "(*)" marks). > >=20 > > 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 =3D 1; - testcancel(curthread); + if (curthread->cancel_async) + testcancel(curthread); break; default: return (EINVAL); --Pe/WPRK8yIcEP0xy Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJRwG/zAAoJEJDCuSvBvK1BP6QP/1etba3gnVLst9yoh4stg0Ls IN8vyjYi1TFjeVL8h77o28RipH481sDt9p3Nqcy8AOg7DRAhUZXcR3ms33bfiuUF xz8ZP+0qYXynX1PJZ1LF1fvcBcZY4EWEIp0J57zuoCfd87p8AKK8xGsMVrC3wVDU 2z7+zehF9zpnWZuZrBwj6f5y48mo1gMvm1H1jthoxTWmckUqnyb4Ys/X+HInHfSX 6aKdzs3SV3fXcYzQjKVoTL4KEs0QL7/FjyPHjVHGp+BvQeAHR2Xw51I64TtYf3Gz axENhEtSg3DnK6SVzn+zwVBF2QZxUfuUylDjE0wbixEQlsUSy5M1f4aaL2DLNinv 3VOT2WIHoFmXk24YHs+2P7ATV0WRBaJYkl7kWaXF2DjFF8Qy8pX0A2ZR3OUfwKuy hN5xGRSDgqk9w2L9Ug/MjLDPIP4zj4Ff1giySu2MvQ1GNfKa8mViVTO/2097qpA8 P7RP8GGTPMI5vUe5JOXfWbYenvMigwlFyaHphiDQwWK5sWfAvFg4s5fmD6s0kUen cHJknczaaSZ0uh6AFMjgvu7LlKNvYN4PndftB1D1/q06cFQkFHStIIchRe6SYo0M 5VAFglLFnN9KHTO9R4Tc8ljIpEUzc5Wbncwkn+ARnpzv24jA+RTLra7OUjAMH7CE lTSSZ7iSw8mKQV3pf+9G =53PI -----END PGP SIGNATURE----- --Pe/WPRK8yIcEP0xy--