From owner-freebsd-threads@FreeBSD.ORG Mon Oct 13 07:18:18 2014 Return-Path: Delivered-To: freebsd-threads@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C4F4F331 for ; Mon, 13 Oct 2014 07:18:18 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ABE34A21 for ; Mon, 13 Oct 2014 07:18:18 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.9/8.14.9) with ESMTP id s9D7IIra035598 for ; Mon, 13 Oct 2014 07:18:18 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-threads@FreeBSD.org Subject: [Bug 194289] cuse_lib.c use a_cuse after unlocking mutex m_cuse -Wthread-safety-analysis Date: Mon, 13 Oct 2014 07:18:18 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: threads X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: hselasky@FreeBSD.org X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-threads@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 07:18:18 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194289 --- Comment #1 from Hans Petter Selasky --- I'll have a look. --HPS -- You are receiving this mail because: You are the assignee for the bug. From owner-freebsd-threads@FreeBSD.ORG Mon Oct 13 19:05:54 2014 Return-Path: Delivered-To: freebsd-threads@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D243F7C1 for ; Mon, 13 Oct 2014 19:05:54 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B9276E8 for ; Mon, 13 Oct 2014 19:05:54 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.9/8.14.9) with ESMTP id s9DJ5s3H029642 for ; Mon, 13 Oct 2014 19:05:54 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-threads@FreeBSD.org Subject: [Bug 194289] cuse_lib.c use a_cuse after unlocking mutex m_cuse -Wthread-safety-analysis Date: Mon, 13 Oct 2014 19:05:55 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: threads X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: commit-hook@freebsd.org X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-threads@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 19:05:54 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194289 --- Comment #2 from commit-hook@freebsd.org --- A commit references this bug: Author: hselasky Date: Mon Oct 13 19:05:19 UTC 2014 New revision: 273059 URL: https://svnweb.freebsd.org/changeset/base/273059 Log: Fix compiler locking diagnostic warnings. PR: 194289 Changes: head/lib/libcuse/cuse_lib.c -- You are receiving this mail because: You are the assignee for the bug. From owner-freebsd-threads@FreeBSD.ORG Mon Oct 13 19:06:34 2014 Return-Path: Delivered-To: freebsd-threads@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D90AD7F3 for ; Mon, 13 Oct 2014 19:06:34 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C0041F4 for ; Mon, 13 Oct 2014 19:06:34 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.9/8.14.9) with ESMTP id s9DJ6YG7030158 for ; Mon, 13 Oct 2014 19:06:34 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-threads@FreeBSD.org Subject: [Bug 194289] cuse_lib.c use a_cuse after unlocking mutex m_cuse -Wthread-safety-analysis Date: Mon, 13 Oct 2014 19:06:35 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: threads X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: hselasky@FreeBSD.org X-Bugzilla-Status: Patch Ready X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-threads@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 19:06:34 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194289 Hans Petter Selasky changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Triage |Patch Ready --- Comment #3 from Hans Petter Selasky --- Can you verify my patch fixes the problem? --HPS -- You are receiving this mail because: You are the assignee for the bug. From owner-freebsd-threads@FreeBSD.ORG Mon Oct 13 21:58:39 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B81E09EF; Mon, 13 Oct 2014 21:58:39 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 92D5B6AB; Mon, 13 Oct 2014 21:58:39 +0000 (UTC) Received: from ralph.baldwin.cx (pool-173-70-85-31.nwrknj.fios.verizon.net [173.70.85.31]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 75DBEB923; Mon, 13 Oct 2014 17:58:36 -0400 (EDT) From: John Baldwin To: freebsd-threads@freebsd.org Subject: Re: sem_post() performance Date: Mon, 13 Oct 2014 17:35:09 -0400 Message-ID: <17114533.JBQOYsdsdz@ralph.baldwin.cx> User-Agent: KMail/4.12.5 (FreeBSD/10.1-BETA2; KDE/4.12.5; amd64; ; ) In-Reply-To: <20140921213742.GA46868@stack.nl> References: <20140921213742.GA46868@stack.nl> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 13 Oct 2014 17:58:36 -0400 (EDT) Cc: adrian@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Oct 2014 21:58:39 -0000 On Sunday, September 21, 2014 11:37:42 PM Jilles Tjoelker wrote: > It has been reported that POSIX semaphores are slow, in contexts such as > Python. Note that POSIX semaphores are the only synchronization objects > that support use by different processes in shared memory; this does not > work for mutexes and condition variables because they are pointers to > the actual data structure. > > In fact, sem_post() unconditionally performs an umtx system call. > > To avoid both lost wakeups and possible writes to a destroyed semaphore, > an uncontested sem_post() must check the _has_waiters flag atomically > with incrementing _count. > > The proper way to do this would be to take one bit from _count and use > it for the _has_waiters flag; the definition of SEM_VALUE_MAX permits > this. However, this would require a new set of umtx semaphore operations > and will break ABI of process-shared semaphores (things may break if an > old and a new libc access the same semaphore over shared memory). Have you thought more about pursuing this option? I think there was a general consensus from earlier in the thread to just break the ABI (at least adjust SEM_MAGIC to give some protection) and fix it. > This diff only affects 32-bit aligned but 64-bit misaligned semaphores > on 64-bit systems, and changes _count and _has_waiters atomically using > a 64-bit atomic operation. It probably needs a may_alias attribute for > correctness, but does not have a wrapper for that. It does have one bug: > + if (atomic_cmpset_rel_64((uint64_t *)&sem->_kern._count, > + oldval, newval)) This needs to be '&_has_waiters'. Right now it changes _count and _flags, but not _has_waiters. -- John Baldwin From owner-freebsd-threads@FreeBSD.ORG Tue Oct 14 20:36:42 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1A5C3C81; Tue, 14 Oct 2014 20:36:42 +0000 (UTC) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id D5889208; Tue, 14 Oct 2014 20:36:41 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 94107B840F; Tue, 14 Oct 2014 22:36:38 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 835B428494; Tue, 14 Oct 2014 22:36:38 +0200 (CEST) Date: Tue, 14 Oct 2014 22:36:38 +0200 From: Jilles Tjoelker To: John Baldwin Subject: Re: sem_post() performance Message-ID: <20141014203638.GA23965@stack.nl> References: <20140921213742.GA46868@stack.nl> <17114533.JBQOYsdsdz@ralph.baldwin.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <17114533.JBQOYsdsdz@ralph.baldwin.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: adrian@freebsd.org, freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Oct 2014 20:36:42 -0000 On Mon, Oct 13, 2014 at 05:35:09PM -0400, John Baldwin wrote: > On Sunday, September 21, 2014 11:37:42 PM Jilles Tjoelker wrote: > > It has been reported that POSIX semaphores are slow, in contexts such as > > Python. Note that POSIX semaphores are the only synchronization objects > > that support use by different processes in shared memory; this does not > > work for mutexes and condition variables because they are pointers to > > the actual data structure. > > In fact, sem_post() unconditionally performs an umtx system call. > > To avoid both lost wakeups and possible writes to a destroyed semaphore, > > an uncontested sem_post() must check the _has_waiters flag atomically > > with incrementing _count. > > The proper way to do this would be to take one bit from _count and use > > it for the _has_waiters flag; the definition of SEM_VALUE_MAX permits > > this. However, this would require a new set of umtx semaphore operations > > and will break ABI of process-shared semaphores (things may break if an > > old and a new libc access the same semaphore over shared memory). > Have you thought more about pursuing this option? I think there was a > general consensus from earlier in the thread to just break the ABI (at > least adjust SEM_MAGIC to give some protection) and fix it. I think this is a good direction but I haven't gotten around to it yet. > > This diff only affects 32-bit aligned but 64-bit misaligned semaphores > > on 64-bit systems, and changes _count and _has_waiters atomically using > > a 64-bit atomic operation. It probably needs a may_alias attribute for > > correctness, but does not have a wrapper for that. > It does have one bug: > > + if (atomic_cmpset_rel_64((uint64_t *)&sem->_kern._count, > > + oldval, newval)) > This needs to be '&_has_waiters'. Right now it changes _count and _flags, > but not _has_waiters. This is probably because I was mistaken about the order of _count and _has_waiters, and only partially corrected that. Anyway, the strange alignment requirements make the patch of little practical use. -- Jilles Tjoelker From owner-freebsd-threads@FreeBSD.ORG Tue Oct 14 21:35:44 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E343DBD5; Tue, 14 Oct 2014 21:35:44 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BDA53AA3; Tue, 14 Oct 2014 21:35:44 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id B5B1EB923; Tue, 14 Oct 2014 17:35:43 -0400 (EDT) From: John Baldwin To: Jilles Tjoelker Subject: Re: sem_post() performance Date: Tue, 14 Oct 2014 17:31:42 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20140415; KDE/4.5.5; amd64; ; ) References: <20140921213742.GA46868@stack.nl> <17114533.JBQOYsdsdz@ralph.baldwin.cx> <20141014203638.GA23965@stack.nl> In-Reply-To: <20141014203638.GA23965@stack.nl> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201410141731.42666.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 14 Oct 2014 17:35:43 -0400 (EDT) Cc: adrian@freebsd.org, freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Oct 2014 21:35:45 -0000 On Tuesday, October 14, 2014 4:36:38 pm Jilles Tjoelker wrote: > On Mon, Oct 13, 2014 at 05:35:09PM -0400, John Baldwin wrote: > > On Sunday, September 21, 2014 11:37:42 PM Jilles Tjoelker wrote: > > > It has been reported that POSIX semaphores are slow, in contexts such as > > > Python. Note that POSIX semaphores are the only synchronization objects > > > that support use by different processes in shared memory; this does not > > > work for mutexes and condition variables because they are pointers to > > > the actual data structure. > > > > In fact, sem_post() unconditionally performs an umtx system call. > > > > To avoid both lost wakeups and possible writes to a destroyed semaphore, > > > an uncontested sem_post() must check the _has_waiters flag atomically > > > with incrementing _count. > > > > The proper way to do this would be to take one bit from _count and use > > > it for the _has_waiters flag; the definition of SEM_VALUE_MAX permits > > > this. However, this would require a new set of umtx semaphore operations > > > and will break ABI of process-shared semaphores (things may break if an > > > old and a new libc access the same semaphore over shared memory). > > > Have you thought more about pursuing this option? I think there was a > > general consensus from earlier in the thread to just break the ABI (at > > least adjust SEM_MAGIC to give some protection) and fix it. > > I think this is a good direction but I haven't gotten around to it yet. Ok, I might take a stab at it. > > > This diff only affects 32-bit aligned but 64-bit misaligned semaphores > > > on 64-bit systems, and changes _count and _has_waiters atomically using > > > a 64-bit atomic operation. It probably needs a may_alias attribute for > > > correctness, but does not have a wrapper for that. > > > It does have one bug: > > > > + if (atomic_cmpset_rel_64((uint64_t *)&sem->_kern._count, > > > + oldval, newval)) > > > This needs to be '&_has_waiters'. Right now it changes _count and _flags, > > but not _has_waiters. > > This is probably because I was mistaken about the order of _count and > _has_waiters, and only partially corrected that. > > Anyway, the strange alignment requirements make the patch of little > practical use. Correct, though it can be used for an immediate fix on amd64 in a pinch. -- John Baldwin From owner-freebsd-threads@FreeBSD.ORG Fri Oct 17 16:52:24 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7EA595CF; Fri, 17 Oct 2014 16:52:24 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5972FFE0; Fri, 17 Oct 2014 16:52:24 +0000 (UTC) Received: from ralph.baldwin.cx (pool-173-70-85-31.nwrknj.fios.verizon.net [173.70.85.31]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id DB028B945; Fri, 17 Oct 2014 12:52:22 -0400 (EDT) From: John Baldwin To: freebsd-threads@freebsd.org Subject: Re: sem_post() performance Date: Fri, 17 Oct 2014 12:48:54 -0400 Message-ID: <7085436.G0Uv0KIisk@ralph.baldwin.cx> User-Agent: KMail/4.12.5 (FreeBSD/10.1-BETA2; KDE/4.12.5; amd64; ; ) In-Reply-To: <201410141731.42666.jhb@freebsd.org> References: <20140921213742.GA46868@stack.nl> <20141014203638.GA23965@stack.nl> <201410141731.42666.jhb@freebsd.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 17 Oct 2014 12:52:22 -0400 (EDT) Cc: adrian@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Oct 2014 16:52:24 -0000 On Tuesday, October 14, 2014 05:31:42 PM John Baldwin wrote: > On Tuesday, October 14, 2014 4:36:38 pm Jilles Tjoelker wrote: > > On Mon, Oct 13, 2014 at 05:35:09PM -0400, John Baldwin wrote: > > > On Sunday, September 21, 2014 11:37:42 PM Jilles Tjoelker wrote: > > > > It has been reported that POSIX semaphores are slow, in contexts such > > > > as > > > > Python. Note that POSIX semaphores are the only synchronization > > > > objects > > > > that support use by different processes in shared memory; this does > > > > not > > > > work for mutexes and condition variables because they are pointers to > > > > the actual data structure. > > > > > > > > In fact, sem_post() unconditionally performs an umtx system call. > > > > > > > > To avoid both lost wakeups and possible writes to a destroyed > > > > semaphore, > > > > an uncontested sem_post() must check the _has_waiters flag atomically > > > > with incrementing _count. > > > > > > > > The proper way to do this would be to take one bit from _count and use > > > > it for the _has_waiters flag; the definition of SEM_VALUE_MAX permits > > > > this. However, this would require a new set of umtx semaphore > > > > operations > > > > and will break ABI of process-shared semaphores (things may break if > > > > an > > > > old and a new libc access the same semaphore over shared memory). > > > > > > Have you thought more about pursuing this option? I think there was a > > > general consensus from earlier in the thread to just break the ABI (at > > > least adjust SEM_MAGIC to give some protection) and fix it. > > > > I think this is a good direction but I haven't gotten around to it yet. > > Ok, I might take a stab at it. I have an implementation of this at https://reviews.freebsd.org/D961 -- John Baldwin