Article View: comp.lang.c++
Article #1135Re: Fwd: futexes vs. system semaphores
From: Chris M. Thomasson
Date: Fri, 04 Dec 2026 23:13
Date: Fri, 04 Dec 2026 23:13
65 lines
3577 bytes
3577 bytes
On 12/4/2026 3:08 PM, Ross Finlayson wrote:
> On 12/04/2026 02:54 PM, Chris M. Thomasson wrote:
>> On 12/4/2026 2:28 PM, Chris M. Thomasson wrote:
>>> 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?
>> >>> void FtxSema::release()
>> >>> {
>> >>> m_ftx = 1;
>> >>> m_ftx.notify_one();
>> >>> }
>>
>> Scares me. The m_ftx.notify_one() better have an internal fast-path in
>> the implementation. I hope it does not just call, say:
>>
>> WaitOnAddress
>
>
> Yeah, one wants to be careful about adopting new techniques.
I messed up. I meant WakeByAddressSingle, NOT WaitOnAddress, GRRR Sorry.
>
> The other day or this morning on the video pile there's
> this Leahy on "Lightning Talk: I'm Not Unreasonable for
> Expecting Functions to Return", where he points out a story
> about learning that io_uring was un-reliable.
>
>
Technical Details
Message-ID:
<11evhe0$258s6$4@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> <11eveqi$24221$1@dont-email.me> <11evgbi$24qkv$1@dont-email.me> <uB6cnR35nvtk2o72nZ2dnZfqnPidnZ2d@giganews.com>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 15:13:04 -0800 Organization: A noiseless patient Spider Lines: 65 Message-ID: <11evhe0$258s6$4@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> <11eveqi$24221$1@dont-email.me> <11evgbi$24qkv$1@dont-email.me> <uB6cnR35nvtk2o72nZ2dnZfqnPidnZ2d@giganews.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 04 Dec 2026 23:13:05 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2270086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PKJ7Ym7E868wWRhNirXfgJY86mQKV4Us="; posting-host="b19a3c9bc26d9213a9f72d10babaa512" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:boxBXo7f2x7CpL7VewlpS0/Rvr4= sha256:vA+CI+Xa1QkX3NHehNyMHe6WvozcD0xNFduh8ggebAk= sha1:2YM5274zeeGlSCOvjSfBvG5OC8Q= sha256:nECQz9yaJ7ykldwbtY3niCtXjVmTkgDIZwNUUKhsHqs= Content-Language: en-US In-Reply-To: <uB6cnR35nvtk2o72nZ2dnZfqnPidnZ2d@giganews.com>