Article View: comp.lang.c++
Article #1130Re: Fwd: futexes vs. system semaphores
From: Ross Finlayson
Date: Fri, 04 Dec 2026 23:08
Date: Fri, 04 Dec 2026 23:08
58 lines
3315 bytes
3315 bytes
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.
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:
<uB6cnR35nvtk2o72nZ2dnZfqnPidnZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.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>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-3.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 04 Dec 2026 23:08:41 +0000 Subject: Re: Fwd: futexes vs. system semaphores Newsgroups: comp.lang.c++ 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> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Fri, 4 Dec 2026 15:08:38 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <11evgbi$24qkv$1@dont-email.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <uB6cnR35nvtk2o72nZ2dnZfqnPidnZ2d@giganews.com> Lines: 58 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-jCiUgiLf8pEIIsJNDd/+sYnaK29a/YdLTW4YO/xogfRTO46PGXe5ACjicRtlUiC1M1XAArH33aZhFio!6tTEsoRl9/TZuicAdpSEjZ+wEY3J7gzB+XSTpcO+ZCMY17k18LDFOuYwwYNSOECua1JSpOBxLjQf!GA== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40