From owner-freebsd-current@FreeBSD.ORG Wed Mar 12 20:33:57 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1AFB3F92 for ; Wed, 12 Mar 2014 20:33:57 +0000 (UTC) Received: from aussmtpmrkps320.us.dell.com (aussmtpmrkps320.us.dell.com [143.166.224.254]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BCCAEDCF for ; Wed, 12 Mar 2014 20:33:55 +0000 (UTC) X-Loopcount0: from 64.238.244.148 X-IronPort-AV: E=Sophos;i="4.97,640,1389765600"; d="scan'208";a="108547295" Message-ID: <5320C4A4.7020109@vangyzen.net> Date: Wed, 12 Mar 2014 15:33:40 -0500 From: Eric van Gyzen User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: FreeBSD current Subject: sem_wait(3) is not always a cancellation point Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.17 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: Wed, 12 Mar 2014 20:33:57 -0000 -current: >From my understand of POSIX, sem_wait(3) should always be a cancellation point. However, when the semaphore's count is positive and the caller successfully decrements the count, sem_wait(3) does not call _pthread_testcancel(), so it's not a cancellation point. See this totally contrived test case: http://www.vangyzen.net/FreeBSD/patches/sem_wait_cancel.c This patch seems like an appropriate fix: http://www.vangyzen.net/FreeBSD/patches/sem_wait_cancel.diff It adds a call to _pthread_testcancel() in the same location as _libc_sem_timedwait_compat() in libc/gen/sem.c. Is this a real bug, or am I missing something? Eric