C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Suggestion: non-static member variables for static-duration-only classes

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 4 Oct 2025 19:33:04 +0100
On Saturday, October 4, 2025, Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Saturday, 4 October 2025 07:19:35 Pacific Daylight Time Frederick
> Virchanza
> Gotham via Std-Proposals wrote:
> > FreeNode *const node = &nodes[index];
> > FreeNode *oldHead = freeList.load(std::memory_order_relaxed);
> >
> > do node->next = oldHead;
> > while ( false == freeList.compare_exchange_weak(oldHead, node,
> > std::memory_order_release, std::memory_order_relaxed) );
>
> There's probably an ABA problem here.
>
>


I think it's okay when you're dealing with trivially-destructible objects
stored in static-duration (or at least not-to-be-deallocated) memory.

If you bring dynamic allocation or non-trivial destruction into it, I think
you'll need a tagged pointer for the freeList:

struct TaggedPtr {
    FreeNode *ptr;
    std::uintptr_t tag;
};

So the value of 'tag' gets incremented and can be checked to see if an ABA
problem has occurred.

I'm being very vague here and only skimming over it in my mind, but
something along those lines.

Received on 2025-10-04 18:33:06