🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Fwd: futexes vs. system semaphores

#1106
From: Bonita Montero
Date: Thu, 03 Dec 2026 21:49
37 lines
2460 bytes
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++.

> Also, add this to your test bed:
> https://vorbrodt.blog/2019/02/05/fast-semaphore/

The code sucks since it needs an additional mutex.
Technical Details
Message-ID: <11eso4p$sn9c$1@raubtier-asyl.eternal-september.org>
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!raubtier-asyl.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>

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!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c++
Subject: Re: Fwd: futexes vs. system semaphores
Date: Thu, 3 Dec 2026 22:49:14 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <11eso4p$sn9c$1@raubtier-asyl.eternal-september.org>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 03 Dec 2026 21:49:13 +0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org;
	logging-data="941356"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19c3Kni98P+uurwr3FQh1Y+hjO7OV/iN4o="; posting-host="17cf8e9141147cb146fb1eeb71e228b0"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lo0Hj+JrGn+7o6gXKLdjmM1tLjE= sha256:gKYVeDHtPcF5UEn+JFkzrvogh8YcbGi+9EAbF0k6gII=
	sha1:jsQQAAESWPmRCTWBd90O09est70= sha256:F81E+BpYI/p8R2byHtjHcmzjABFkA8MGYVwNk4CKdmc=
Content-Language: de-DE
In-Reply-To: <11esnho$s9c7$2@dont-email.me>