Article View: comp.lang.c++
Article #822Re: How to write a semaphore with futexes
From: Chris M. Thomasson
Date: Tue, 10 Nov 2026 21:32
Date: Tue, 10 Nov 2026 21:32
16 lines
2118 bytes
2118 bytes
On 11/10/2026 8:40 AM, Bonita Montero wrote: > I wanted to write a semaphore with a futex. I incremented a counter > and did the notify. Oh the other side I did a wait and after the wait > I do a decrement of the counter if it was non-zero, otherwise I wait > again. > The problem with that is that is that I want to wake up another thread > and immediatly wait on the same semaphore on the notifying side it's > very likely that the notifying thread eats up its own notify and the > other thread doesn't consume the notify. This doesn't happen with com- > pletely kernel-managed semaphores. > So it is possible to write a semaphore with a futex without this limi- > tation ? > And: Chris, this isn't a question eligible for short-circuited toughts. > Fwiw, why not use a kernel semaphore as a slow path? Is this just for fun?
Technical Details
Message-ID:
<11d02gm$2h8g0$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cvher$2ahke$1@raubtier-asyl.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: How to write a semaphore with futexes Date: Tue, 10 Nov 2026 13:32:04 -0800 Organization: A noiseless patient Spider Lines: 16 Message-ID: <11d02gm$2h8g0$1@dont-email.me> References: <11cvher$2ahke$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 10 Nov 2026 21:32:07 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2662912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wmW4rRLFGub+MoICSOc6Ji5JmEPfo/2c="; posting-host="3e7af8eaf01208094d9c8c047e2a4497" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:IFlQRS0UxFgNtGrLBibdlPt+DSY= sha256:Qmvi7p5amrf951wIdnz11MLR3zt24nxumqQ+S5nF1gA= sha1:kAjA2d3ZCsPCRthAZ2Q0cZixHPQ= sha256:zpft37Ae9Uv79v4JqxaxJuEpzzXrSlli7ZhAtIb4INA= Content-Language: en-US In-Reply-To: <11cvher$2ahke$1@raubtier-asyl.eternal-september.org>