🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Consequential RCU

#61
From: David Brown
Date: Fri, 09 Oct 2026 06:33
86 lines
6100 bytes
On 09/10/2026 02:13, Chris M. Thomasson wrote:
> On 10/4/2026 2:34 AM, David Brown wrote:
>> On 03/10/2026 23:12, Chris M. Thomasson wrote:
>>> On 10/3/2026 8:50 AM, boltar@caprica.universe wrote:
>>>> On Sat, 3 Oct 2026 14:19:56 +0200
>>>> David Brown <david.brown@hesbynett.no> gabbled:
>>>>> On 02/10/2026 20:13, Chris M. Thomasson wrote:
>>>>>> It should be something akin to, why do I feel the need to code 
>>>>>> this is ASM when the C/C++11 should already do it for me. That 
>>>>>> type of angle?
>>>>>
>>>>> Something along these lines should be fine.  There may be some 
>>>>> underlying reason why this is implemented as a library call in 
>>>>> gcc's C++ standard library, rather than a direct lock-free opcode.  
>>>>> I don't know the details of any of this - maybe there are flaws in 
>>>>> some chips, maybe the single op-code actually takes longer than a 
>>>>> lock- based implementation.  Maybe it's just that no one has got 
>>>>> round to implementing it yet.
>>>>
>>>> I would guess the reason is consistent behaviour across different 
>>>> architectures.
>>>>
>>>
>>> Well, if the library call goes to LOCK CMPXCHG16B for what we need it 
>>> for then that would be okay. We need to step into the library call to 
>>> find out.
>>
>>  From what I have looked at, including the bugzilla link Joseph 
>> posted, there seem to be a number of complications involved.  A 
>> particular sticking point is that you can't have lock-free C++ 
>> standard atomic types without also having atomic load and store 
>> operations of the same size.  And while the 16-byte CAS can be used 
>> for loads and stores, it can't be used for 16-byte atomic loads on 
>> read-only memory.  This means that on older 64-bit x86 processors, 16- 
>> byte atomic types cannot be lock-free even if they support 16-byte CAS.
> 
> Shit... Well, damn that kind of ruins things. Well, because I do not 
> even need atomic loads/stores of the DWCAS (aka, two contiguous words)!
> 
> Sigh. I just want C++ to have a always lock-free DWCAS on systems that 
> support it. The loads and stores do not even need to be there. But, see, 
> that is for my personal use. Sigh. Not good enough for the std?
> 

Standard libraries are not about individuals.

"Always lock-free" means /always/ lock-free.  If the target does not 
support lock-free versions of all the operations on the atomic type, the 
atomic type is not "always lock-free".  (As far as I can tell, this is a 
limitation of the x86 processors, perhaps also partly a failure of AMD 
and Intel to document guarantees about atomic loads and stores.  It is 
not a failure of the gcc C++ standard library.)

> 
>>
>> It seems that the libatomic implementation does, in some cases, use 
>> the CMPXCHG16B instruction rather than a mutex. 
> Thank GOD! Then they can make their C++ impl report that this is always 
> lock-free?

Or perhaps thank the libatomic authors and the GCC C++ standard library 
implementers for making a correct implementation?

No, their library cannot say that 128-bit types are "always lock-free" 
unless they /are/ always lock-free.  You can always test gcc 17 with the 
"-m128bit-atomic" flag, assuming you have an appropriate target 
processor (or just look at it on godbolt.org).

> 
>> The exact code run in the library depends on the cpuid of the 
>> processor, as well as compiler flags.  (The default "lowest common 
>> denominator" x86-64 instruction set does not support CMPXCHG16B.)
>>
>> So the C++ standard library atomics do not lead directly to the use of 
>> the lock-free instruction.  But if you have the "-mxc16" compiler flag 
>> (or use a -march flag for a cpu family that supports it), then you can 
>> use the low-level builtin __sync_bool_compare_and_swap to generate it.
>>
>> Better still, in gcc 17 (in development) you can use the "-m128bit- 
>> atomic" flag to get full 16-byte atomics on processors for which the 
>> GCC folks have assurances from Intel or AMD that the 128-bit SSE2 
>> vector loads and stores are atomic.  You can try this on godbolt.org.
>>
>>
> 
Technical Details
Message-ID: <11aa1qv$hao8$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <118f4vv$3plsv$1@dont-email.me> <118mrl9$2j5vk$1@dont-email.me> <118os9o$36ell$1@dont-email.me> <118pp3b$3hhhe$2@dont-email.me> <118r96b$3ubta$1@dont-email.me> <118rjhu$3h1al$1@dont-email.me> <118rmuv$4lbb$1@dont-email.me> <11967a6$3oc1h$1@raubtier-asyl.eternal-september.org> <1196c4f$3q9m3$1@dont-email.me> <1196g18$3rvnj$1@dont-email.me> <1196oje$3v5oj$1@dont-email.me> <1198dcn$feci$1@dont-email.me> <11996sr$ob49$1@dont-email.me> <119b3pl$1ahkb$1@dont-email.me> <119er16$2pe7v$1@dont-email.me> <119flvc$316ju$1@dont-email.me> <119os83$2bmlo$2@dont-email.me> <119qrtc$306a9$1@dont-email.me> <119r87l$34smh$1@dont-email.me> <119rr3b$3c208$1@dont-email.me> <119t6j5$3oplg$1@dont-email.me> <11a9bim$b09r$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c++
Subject: Re: Consequential RCU
Date: Fri, 9 Oct 2026 08:33:03 +0200
Organization: A noiseless patient Spider
Lines: 86
Message-ID: <11aa1qv$hao8$1@dont-email.me>
References: <118f4vv$3plsv$1@dont-email.me> <118mrl9$2j5vk$1@dont-email.me>
 <118os9o$36ell$1@dont-email.me> <118pp3b$3hhhe$2@dont-email.me>
 <118r96b$3ubta$1@dont-email.me> <118rjhu$3h1al$1@dont-email.me>
 <118rmuv$4lbb$1@dont-email.me>
 <11967a6$3oc1h$1@raubtier-asyl.eternal-september.org>
 <1196c4f$3q9m3$1@dont-email.me> <1196g18$3rvnj$1@dont-email.me>
 <1196oje$3v5oj$1@dont-email.me> <1198dcn$feci$1@dont-email.me>
 <11996sr$ob49$1@dont-email.me> <119b3pl$1ahkb$1@dont-email.me>
 <119er16$2pe7v$1@dont-email.me> <119flvc$316ju$1@dont-email.me>
 <119os83$2bmlo$2@dont-email.me> <119qrtc$306a9$1@dont-email.me>
 <119r87l$34smh$1@dont-email.me> <119rr3b$3c208$1@dont-email.me>
 <119t6j5$3oplg$1@dont-email.me> <11a9bim$b09r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 09 Oct 2026 06:33:04 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="568072"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+/KN/OEajk+1+TudYuY3+7/djstGSpyCY="; posting-host="e4f5a948a55ca956d08d1b630ba49c87"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:o3Xi0CepdDpn99hJqiRQdeyX99w= sha256:lEODEWAqajyjgr2XXndsVcBQzGtyJkaAwZj0jwlXzhA=
	sha1:lvfo94aEVQNwR+lDR0hSXtXa3q4= sha256:qL0uaCHLqH9pMJCIr3PdyqH5VoopHf9NZ+uXNyggrbo=
In-Reply-To: <11a9bim$b09r$1@dont-email.me>
Content-Language: en-GB