Article View: comp.lang.c++
Article #1108Re: Fwd: futexes vs. system semaphores
From: Chris M. Thomasson
Date: Thu, 03 Dec 2026 22:30
Date: Thu, 03 Dec 2026 22:30
47 lines
2892 bytes
2892 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++.
Then its crap.
>
>> Also, add this to your test bed:
>> https://vorbrodt.blog/2019/02/05/fast-semaphore/
>
> The code sucks since it needs an additional mutex.
lol. You can exchange:semaphore m_semaphore; The slow path semaphow with
an arch specific kernel semaphore if you want. Also, you don't seem to
understand the code at all. See, the slow path semaphore used there is
emulated with a mutex/condvar, fine. This can be a kernel semaphore. Get
over it.
Technical Details
Message-ID:
<11esqj0$tq1m$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: Thu, 3 Dec 2026 14:30:55 -0800 Organization: A noiseless patient Spider Lines: 47 Message-ID: <11esqj0$tq1m$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: Thu, 03 Dec 2026 22:30:57 +0000 (UTC) Injection-Info: dont-email.me; logging-data="976950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wrwOJe3vDRs4S3jO9kQekKLFXqcSnX+8="; posting-host="27be630b90107ef0dd0e5ccb8f536ba4" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:gIhwQ2XveR4CDpqMt7FurBslQ9c= sha256:ydI1CtW6i6nu1siZ2gkkSYff/UsAdtGdyskiQsQ2Q9I= sha1:jtHH4XHcwD6IkMWPrETMwxk5rTk= sha256:o0szDSIK0EmAMUpgbllr0kocYj7bzB4INmC8787PLic= In-Reply-To: <11eso4p$sn9c$1@raubtier-asyl.eternal-september.org> Content-Language: en-US