🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Fwd: futexes vs. system semaphores

#1142
From: Chris M. Thomasson
Date: Fri, 04 Dec 2026 23:28
67 lines
3672 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.
> 
> 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.
> 
> 

Bonita has no idea what a semaphore is. Try this with his code:

     FtxSema s(false);
     s.release();
     s.release();
     s.acquire();
     s.acquire();  // hangs
Technical Details
Message-ID: <11eviao$25mm2$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-mail
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>

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:28:24 -0800
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <11eviao$25mm2$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:28:25 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2284226"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18o8L2sNROjnMIWNGEjE4OmCdnUrtVTAEE="; posting-host="b19a3c9bc26d9213a9f72d10babaa512"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GcDD0wntKuxvfIx+Z0dBtIQIeD0= sha256:osM6+1zgI4z+KumpujxNts8+pLcab/YpeoNDoNSY3MU=
	sha1:MMfHqWvWMPCNAgdIrn/ThLCULPE= sha256:CLXD+/0WVXxi56XKw6YLh/wjz5Tpr4rgfh/Y/qnd468=
In-Reply-To: <uB6cnR35nvtk2o72nZ2dnZfqnPidnZ2d@giganews.com>
Content-Language: en-US