Article View: comp.lang.c++
Article #1120Re: Fwd: futexes vs. system semaphores
From: Chris M. Thomasson
Date: Fri, 04 Dec 2026 22:28
Date: Fri, 04 Dec 2026 22:28
46 lines
2760 bytes
2760 bytes
On 12/3/2026 1:49 PM, Bonita Montero wrote:
> Am 03.12.2026 um 22:39 schrieb Chris M. Thomasson:
>
>> You should measure how many times the fast path gets hit:
>>
>> void FtxSema::acquire()
>> {
>> for( int ftx = m_ftx; ; )
>> if( ftx )
>> if( m_ftx.compare_exchange_strong( ftx, 0 ) )
>> return;
>> else
>> continue;
>> else
>> {
>> m_ftx.wait( 0 );
>> ftx = m_ftx;
>> }
>> }
>>
>>
>> Also, you need to try to fast path the release:
>>
>> void FtxSema::release()
>> {
>> m_ftx = 1;
>> m_ftx.notify_one();
>> }
>>
>>
>> Your futex sema is not all that good.
>
> It works exactly like the counting semaphores of the libstdc++.
FtxSema::release() is NO good is always a slow path. Did you look at the
actual futex implementation?
>
>> Also, add this to your test bed:
>> https://vorbrodt.blog/2019/02/05/fast-semaphore/
>
> The code sucks since it needs an additional mutex.
You are missing the forest for the trees here. That is the SLOW path.
Got it?
Technical Details
Message-ID:
<11eveqi$24221$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11duih8$sm6c$1@raubtier-asyl.eternal-september.org> <11duq79$vfpt$1@raubtier-asyl.eternal-september.org> <11er4jp$10h0$1@raubtier-asyl.eternal-september.org> <11esnho$s9c7$2@dont-email.me> <11eso4p$sn9c$1@raubtier-asyl.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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: Fwd: futexes vs. system semaphores Date: Fri, 4 Dec 2026 14:28:34 -0800 Organization: A noiseless patient Spider Lines: 46 Message-ID: <11eveqi$24221$1@dont-email.me> References: <11duih8$sm6c$1@raubtier-asyl.eternal-september.org> <11duq79$vfpt$1@raubtier-asyl.eternal-september.org> <11er4jp$10h0$1@raubtier-asyl.eternal-september.org> <11esnho$s9c7$2@dont-email.me> <11eso4p$sn9c$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 04 Dec 2026 22:28:35 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2230337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/d5xqNydJfdKH4Nw6aSbnRdQBQCdQwtYw="; posting-host="b19a3c9bc26d9213a9f72d10babaa512" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:70S7zzG4P2FXL5Jb+mmLlr/z8CQ= sha256:M0Nr7WwByfAAT7dVkIn4Y5pQVmDKSTw1UjrE19H6OmY= sha1:bxDVZeJGf6HipUJl2xNsIp1Pnvw= sha256:xIC72Dyr9x4BXOO+TfEj7pQilGWAvsppsxPLjvJfZH4= Content-Language: en-US In-Reply-To: <11eso4p$sn9c$1@raubtier-asyl.eternal-september.org>