Article View: comp.lang.c++
Article #306Re: Consequential RCU
From: Chris M. Thomasson
Date: Mon, 12 Oct 2026 19:58
Date: Mon, 12 Oct 2026 19:58
101 lines
6998 bytes
6998 bytes
On 10/8/2026 11:33 PM, David Brown wrote: > 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.) I understand. I am only interested in if a fallback to a library, or whatever, uses the LOCK CMPXCHG16B on x64. Or any other arch if they support a native double-width CAS (DWCAS) instruction. LL/SC aside for a moment... It might be interesting if I can infer if say DWCAS was always lock-free but DW atomic loads/stores are not. That is fine with me. >>> 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? Ponder on those implementers as akin to a "god"... lol. ;^) Way before C++11, implementing these things in per-arch ASM was my gold std. LTO aside for a moment... Uggg. I was scared/paranoid of a compiler trying to do some funny business with my results (.o) files, from GAS/MASM. > 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). Indeed. >>> 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. Shit happens. This is a rather niche area anyway.
Technical Details
Message-ID:
<11aje4d$3uhrs$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-mailReferences:
<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> <11aa1qv$hao8$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: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: Consequential RCU Date: Mon, 12 Oct 2026 12:58:03 -0700 Organization: A noiseless patient Spider Lines: 101 Message-ID: <11aje4d$3uhrs$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> <11aa1qv$hao8$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 12 Oct 2026 19:58:06 +0000 (UTC) Injection-Info: dont-email.me; logging-data="4147068"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+b9BvcwNxBoSq12kw/bPrqbN61Ne1qbvY="; posting-host="23695f1b3419bf2835ebd55b3868dbf0" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:VJ9wbq5en5JNJltKijxSCF20rFg= sha256:B7vUo+Ldkdfo6Iw1iciLXCB7fiBrYos1diGSDwSidXs= sha1:D7iC7HvFkIsfNMAdDgvqc45emJc= sha256:2M+pmXKSFu6ypHR0QHY0SoxD8iS171suvbJ6y3KaQrw= In-Reply-To: <11aa1qv$hao8$1@dont-email.me> Content-Language: en-US