🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

FtxSema is a binary semaphore, not a general one (and a counting futex version)

#1150
From: Chris M. Thomasson
Date: Sat, 05 Dec 2026 00:33
16 lines
1822 bytes
In the futex vs. system semaphore benchmark, FtxSema is named a 
semaphore, but it's a binary semaphore (effectively an auto-reset 
event). release() does m_ftx = 1, so releases don't accumulate:

FtxSema s(false);
s.release();
s.release();
s.acquire();
s.acquire();   // blocks forever; a counting semaphore would not

This is deterministic and single-threaded. It matters for any use where 
releases can outnumber acquires, such as producer/consumer queues where 
N posts must allow N waits.

For some reason I was under the impression that it was a normal 
semaphore. Sigh. Sorry.
Technical Details
Message-ID: <11evm5c$27kcm$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.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: FtxSema is a binary semaphore, not a general one (and a counting
 futex version)
Date: Fri, 4 Dec 2026 16:33:46 -0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <11evm5c$27kcm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 05 Dec 2026 00:33:49 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2347414"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18fMHYPKaQcGzcks/A97qC0Eu/p+1xUeH4="; posting-host="2b66e3b9720a5537939852d7aa1235e3"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:N8LUvh1k5I7PPXFVKA1fZG4JDRA= sha256:3HBFCK8zToAfaO3+rBxt4pyBs/n0FDK44PO8jxX0naI=
	sha1:38seSjj+uqOjbHE+ctTNAvlh6rg= sha256:ngm6YEfFBdDzXGYl/pvqwMNb+OUQNt+xbCEGXpbntRw=
Content-Language: en-US