🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #815

How to write a semaphore with futexes

#815
From: Bonita Montero
Date: Tue, 10 Nov 2026 16:40
13 lines
1898 bytes
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.
Technical Details
Message-ID: <11cvher$2ahke$1@raubtier-asyl.eternal-september.org>
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!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail

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!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c++
Subject: How to write a semaphore with futexes
Date: Tue, 10 Nov 2026 17:40:58 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <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 16:40:59 +0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org;
	logging-data="2442894"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19ipio5WWxym4Ua6FCZJARaRwJ+nO2l1xE="; posting-host="56ff4c394e0a125ecea6c9f71e11e9c9"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ys+sDujNvRVzylP+X1wwhiD5Qmg= sha256:lc8rww6eC8nKbXlPcDXw6cpg+UwFHI+JqglYZiJcBhg=
	sha1:BKYARnRYQ9ZQHy7MIg21TO+Tde8= sha256:UDWH0beWcPEY+N8QVJ+YzkDtz7NyttInr0x1HIEZ07U=
Content-Language: de-DE