On 02/10/2026 20:11, Chris M. Thomasson wrote:
On 9/30/2026 12:54 AM, David Brown wrote:
On 30/09/2026 01:30, Chris M. Thomasson wrote:
On 9/28/2026 11:40 PM, David Brown wrote:
gcc inline assembly is a /much/ better solution here.ÿ It's okay if >>>>> you don't know how to write it - and it is certainly okay if youDifficult to totally disagree with that David. Shit. Its my own
did not know how to do so a decade ago.ÿ But you should understand
why it is better, and then decide if you are going to learn about it. >>>>>
(Of course for this particular case, if you can persuade the gcc C+ >>>>> + library folk to make their standard cas16 lock-free, then using
the standard function is best.)
personal problem with the syntax of GCC inline asm. I am a bit
scared of it. Sigh. Clobbers what? When and where? cdecl for the ABI
and externally assembled functions are fine for me, LTO aside for a
moment, can be bad do not go into my asm! BUT. Again. Shit. Its a
personal problem wrt me saying inline bad! Sorry!
Not knowing the syntax for gcc inline assembly is not a "problem" as
such - most C programmers never need it.ÿ It is just a strong
recommendation that /if/ you want to write assembly code, then your
results would be much improved by using inline assembly format rather
than external assembly functions.ÿ And you are already familiar with
the hard part, the actual assembly.ÿ So don't look at this as a
problem of any sort - look at it as a fun, challenging and useful new
direction for your existing skills and interests.
Also, if C++ gains a LOCK CMPXCHG16B for a double word, two
contiguous 64 bit words on a 64 bit machine, well GOOD! Show me. I
have had some experiences with it trying to tell me its not lock free.
The C++ standard library supports 16 byte compare-and-exchange.ÿ The
gcc implementation of that library does not use that instruction, and
thus does not support lock-free 16 byte compare-and-exchange.ÿ C++
has supported this since C++11 - this is a QOI issue, not a language
or standard library issue.ÿ File an issue on the gcc bugzilla -
that's how you get progress (or how we will learn if there are good
reasons not to use it.)
I first need to show why its a qoi to begin with. If the arch supports
a single instruction for a double word atomic rmw op (DWCAS), it
should be using that instruction. And! it needs to report it as always
lock-free. Then the user has all the info they need for a fallback to
asm. Then show a bunch of examples where its needed. But that should
not be all that hard. Say okay, if the C/C++ does not make this atomic
RMW lock- free on an arch that supports it, then its useless for
anything lock- free on said arch. ASM to the rescue?
The inline asm certainly gives you a way to get efficient use of the instruction before it is in the toolchain implementation.ÿ But the
toolchain implementation is the best long-term solution.ÿ So do both -
use the inline asm yourself while encouraging gcc to implement it in
their library for the future.
Am 09.10.2026 um 03:10 schrieb Chris M. Thomasson:
I am not sure if you understand your own idea. ...
You keep missing the point, and then you say something like that ?
On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
On 10/13/2026 10:01 AM, Joseph Seigh wrote:
On 10/11/26 11:11 AM, Joseph Seigh wrote:
This is what the code I did a quick and dirty test with looked like
using csequence_t = uint64_t;
inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
sequence)
{
ÿÿÿÿ std::atomic_thread_fence(std::memory_order_acquire);
ÿÿÿÿ return mark != sequence.load(std::memory_order_acquire);
}
csequence_t mark;
retry:
do {
ÿÿÿÿ mark = cseq_count.load(std::memory_order_acquire);
ÿÿÿÿ node_t * item = list.load(std::memory_order_acquire);
ÿÿÿÿ for (int ndx2 = 0; ndx2 < depth; ndx2++) {
ÿÿÿÿÿÿÿÿ item = item->next.load(std::memory_order_acquire);
ÿÿÿÿÿÿÿÿ if (cseq_retry(mark, cseq_count)) [[unlikely]]
ÿÿÿÿÿÿÿÿÿÿÿÿ goto retry;
ÿÿÿÿ }
} while (cseq_retry(mark, cseq_count));
Oh shit. This looks like it can be _potential_ "livelock" nation under
some sustained periods of "heavy enough" load? Can we iterate the
whole list before many (n) retrys have occurred? Or how many retrys on
average does it take to iterate a decent sized list from head to tail?
Writers churning along in the background...
The list was used to give an idea how much overhead there would be.
I wouldn't use this for O(n) stuff where n is very large.
In that this is similar to SEQLOCK, its docs mention the livelock issue.
The term for these kind of algorithms is obstruction-free (Herlihy).
You could avoid this with a conventional rwlock. Probably slow you
down by orders of magnitude.
You could use RCU since the readers are wait-free.ÿ With that many
updates deferring that much memory, you might OOM.
On 10/15/2026 4:26 PM, Joseph Seigh wrote:
On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
On 10/13/2026 10:01 AM, Joseph Seigh wrote:
On 10/11/26 11:11 AM, Joseph Seigh wrote:
This is what the code I did a quick and dirty test with looked like
using csequence_t = uint64_t;
inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
sequence)
{
std::atomic_thread_fence(std::memory_order_acquire);
return mark != sequence.load(std::memory_order_acquire);
}
csequence_t mark;
retry:
do {
mark = cseq_count.load(std::memory_order_acquire);
node_t * item = list.load(std::memory_order_acquire);
for (int ndx2 = 0; ndx2 < depth; ndx2++) {
item = item->next.load(std::memory_order_acquire);
if (cseq_retry(mark, cseq_count)) [[unlikely]]
goto retry;
}
} while (cseq_retry(mark, cseq_count));
Oh shit. This looks like it can be _potential_ "livelock" nation
under some sustained periods of "heavy enough" load? Can we iterate
the whole list before many (n) retrys have occurred? Or how many
retrys on average does it take to iterate a decent sized list from
head to tail? Writers churning along in the background...
The list was used to give an idea how much overhead there would be.
I wouldn't use this for O(n) stuff where n is very large.
In that this is similar to SEQLOCK, its docs mention the livelock issue.
The term for these kind of algorithms is obstruction-free (Herlihy).
Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
Let me try to find it...
https://sites.google.com/site/1024cores/home/lock-free-algorithms/reader-writer-problem/improved-lock-free-seqlock
You could avoid this with a conventional rwlock. Probably slow you
down by orders of magnitude.
You could use RCU since the readers are wait-free. With that many
updates deferring that much memory, you might OOM.
Yeah. I remember some old stress tests that would make malloc fail. Man
that was a long time ago.
On 11/29/2026 12:57 AM, Chris M. Thomasson wrote:
On 10/15/2026 4:26 PM, Joseph Seigh wrote:
On 10/15/26 2:49 PM, Chris M. Thomasson wrote:
On 10/13/2026 10:01 AM, Joseph Seigh wrote:
On 10/11/26 11:11 AM, Joseph Seigh wrote:
This is what the code I did a quick and dirty test with looked like
using csequence_t = uint64_t;
inline bool cseq_retry(csequence_t mark, std::atomic<csequence_t> &
sequence)
{
ÿÿÿÿ std::atomic_thread_fence(std::memory_order_acquire);
ÿÿÿÿ return mark != sequence.load(std::memory_order_acquire);
}
csequence_t mark;
retry:
do {
ÿÿÿÿ mark = cseq_count.load(std::memory_order_acquire);
ÿÿÿÿ node_t * item = list.load(std::memory_order_acquire);
ÿÿÿÿ for (int ndx2 = 0; ndx2 < depth; ndx2++) {
ÿÿÿÿÿÿÿÿ item = item->next.load(std::memory_order_acquire);
ÿÿÿÿÿÿÿÿ if (cseq_retry(mark, cseq_count)) [[unlikely]]
ÿÿÿÿÿÿÿÿÿÿÿÿ goto retry;
ÿÿÿÿ }
} while (cseq_retry(mark, cseq_count));
Oh shit. This looks like it can be _potential_ "livelock" nation
under some sustained periods of "heavy enough" load? Can we iterate
the whole list before many (n) retrys have occurred? Or how many
retrys on average does it take to iterate a decent sized list from
head to tail? Writers churning along in the background...
The list was used to give an idea how much overhead there would be.
I wouldn't use this for O(n) stuff where n is very large.
In that this is similar to SEQLOCK, its docs mention the livelock issue. >>> The term for these kind of algorithms is obstruction-free (Herlihy).
Fwiw, speaking of SEQLOCK I think Dmitry had a nifty distributed one.
Let me try to find it...
https://sites.google.com/site/1024cores/home/lock-free-algorithms/
reader-writer-problem/improved-lock-free-seqlock
You could avoid this with a conventional rwlock. Probably slow you
down by orders of magnitude.
You could use RCU since the readers are wait-free.ÿ With that many
updates deferring that much memory, you might OOM.
Yeah. I remember some old stress tests that would make malloc fail. Man
that was a long time ago.
Didn't "memory_order" get deprecated.
You either have opportunistic-locking about cmp-exchange | load-linked+store-conditional with a datum of 64-bits about AMD
and aligned and padded to 64-bytes or 128 for ARM's cache-line pairs,
or you don't, then about that there's basically always a necessary UUID-vendor to prevent ABA (i.e., "race conditions"),
one thing that guarantees another being the same ("unique"),
and another guaranteeing another being different ("unique").
You could use RCU since the readers are wait-free.ÿ With that many
updates deferring that much memory, you might OOM.
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 3 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 51:06:26 |
| Calls: | 223 |
| Files: | 21,513 |
| Messages: | 83,422 |