🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Chris M. Thomasson Fri, 09 Oct 2026 00:15
Re: Consequential RCU
#49
Author: Chris M. Thomasson
Date: Fri, 09 Oct 2026 00:15
56 lines
4832 bytes
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.
> 
> It seems that the libatomic implementation does, in some cases, use the 
> CMPXCHG16B instruction rather than a mutex.  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.
> 
> 

Well, see, just because I need to use DWCAS (LOCK CMPXCHG16B) on x64, 
for certain algos does not mean I want full double adjacent word loads 
and stores. That is besides the point.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads