🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Fwd: futexes vs. system semaphores

#1134
From: Chris M. Thomasson
Date: Fri, 04 Dec 2026 23:12
50 lines
3083 bytes
On 12/4/2026 2: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

God damn it! I meant: WakeByAddressSingle DOH! Sorry everybody.
Technical Details
Message-ID: <11evhcn$258s6$3@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>

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:12:22 -0800
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <11evhcn$258s6$3@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 04 Dec 2026 23:12:23 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2270086"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+qavOUaFhkkfRYJ9WN/E4I6YRISiYzv/A="; posting-host="b19a3c9bc26d9213a9f72d10babaa512"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LJ7F/tf6y9bq3MIirsud9kB0TSE= sha256:KvwDmpgL9kBOn8CzTkZm+MkCEjO1INTXyuowQqASqBY=
	sha1:qxiuRZXtCdYdKw5QsLFV1mHvelo= sha256:WNHehvXKex2O5lRiBym705YK3khlMaL/DSRQnQZwAf4=
In-Reply-To: <11evgbi$24qkv$1@dont-email.me>
Content-Language: en-US