🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Consequential RCU

#536
From: Chris M. Thomasson
Date: Tue, 13 Oct 2026 23:46
218 lines
7768 bytes
On 10/13/2026 4:34 PM, Joseph Seigh wrote:
> On 10/13/26 3:36 PM, Chris M. Thomasson wrote:
>> On 10/13/2026 10:01 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));
>>>
>>>
>>> As you can see, not a heck of lot of room in that loop
>>> for the cpu pipeline to deal with the extra load and
>>> conditional logic.
>>>
>>
>> It seems like cseq_retry on "every" iteration with its, two?, 
>> #LoadStore | #LoadLoad barriers is a bit much. Now that I have Relacy 
>> working fine on my end, and it has all I need for simulating even 
>> advanced RCU+SMR algos. Well, I will get back into it from time to 
>> time. Actually, can you get it working? Its a neat way to simulate 
>> your sync experiments.
>>
>> Wait I count an acquire on the item->next.load and then two acquires 
>> from cseq_retry? Am I missing something critical here Joe?
> 
> It would appear that way.   That's what quick and dirty means. :)
> If the redundant load/load gets take out then there needs to be
> some other mechanism or documentation to ensure the loads are in
> order.
> 
> 

Shit. Yeah... Well, humm... For some damn reason Joe, it kinda sorta 
makes me ponder on why Relacy experiment goes "berserk" if I remove the 
consume membar from my smr_load: I sent an email to Dmitriy about it.

I need to start getting dinner ready right now, but I am a bit baffled 
by it:

___________________
per_node*
smr_load(
     unsigned long tidx
) {
     for (;;)
     {
         per_node* node0 = m_node.load(rl::mo_relaxed, $);

         if (! node0)
         {
             RL_ASSERT(0);
             break;
         }

         m_threads[tidx].m_haz_0.store(node0, rl::mo_relaxed, $);

         // actually, iirc, a single seq_cst right here should work?

         per_node* node1 = m_node.load(rl::mo_consume, $);

         if (node0 == node1)
         {
             return node0;
         }
     }

     return nullptr;
}
___________________



my poller uses the systemwide_fence to get the async working:

________________________
struct poller
{
     rl::mutex m_poll;
     VAR_T(per_node*) m_defer0 = nullptr;

     void
     prv_poll(
         per_node*& defer,
         std::array<per_thread, CT_THREADS>& threads
     ) {
         per_node* head = defer;
         defer = nullptr; // Take ownership of the caller's local batch

         // Merge any previously deferred nodes from m_defer0 into the 
processing batch
         per_node* curr = VAR(m_defer0);
         VAR(m_defer0) = nullptr;
         while (curr)
         {
             per_node* next_node = VAR(curr->m_defer);
             VAR(curr->m_defer) = head;
             head = curr;
             curr = next_node;
         }

         // Two-Pass Hazard Pointer Scan:
         // Pass 1: Capture all thread hazard slots
         std::vector<per_node*> haz_pass1(threads.size());
         for (size_t i = 0; i < threads.size(); ++i)
         {
             haz_pass1[i] = threads[i].m_haz_0.load(rl::mo_relaxed, $);
         }

         // Synchronization barrier between scans
         rl::systemwide_fence($);

         // Pass 2: Capture all thread hazard slots again
         std::vector<per_node*> haz_pass2(threads.size());
         for (size_t i = 0; i < threads.size(); ++i)
         {
             haz_pass2[i] = threads[i].m_haz_0.load(rl::mo_relaxed, $);
         }

         per_node* remaining = nullptr;

         while (head)
         {
             per_node* next = VAR(head->m_defer);
             bool protected_node = false;

             // Check if the node is protected in either pass snapshot
             for (auto haz : haz_pass1)
             {
                 if (haz == head)
                 {
                     protected_node = true;
                     break;
                 }
             }

             if (!protected_node)
             {
                 for (auto haz : haz_pass2)
                 {
                     if (haz == head)
                     {
                         protected_node = true;
                         break;
                     }
                 }
             }

             if (protected_node)
             {
                 // Keep it in the deferred list
                 VAR(head->m_defer) = remaining;
                 remaining = head;
             }
             else
             {
                 // Safe to reclaim!
                 delete head;
             }

             head = next;
         }

         // Store any still-protected nodes back into the central poller 
queue
         VAR(m_defer0) = remaining;
     }

     bool
     try_poll(
         per_node*& defer,
         std::array<per_thread, CT_THREADS>& threads
     ) {
         if (m_poll.try_lock($))
         {
             prv_poll(defer, threads);
             m_poll.unlock($);
             return true;
         }

         return false;
     }

     void
     poll(
         per_node*& defer,
         std::array<per_thread, CT_THREADS>& threads
     ) {
         m_poll.lock($);
         prv_poll(defer, threads);
         m_poll.unlock($);
     }
};
________________________


Two passes with the async member in between them.
Technical Details
Message-ID: <11amfsg$10sng$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <118f4vv$3plsv$1@dont-email.me> <11ag8ue$2nvjl$1@dont-email.me> <11alo51$nmur$1@dont-email.me> <11am17q$rl8q$1@dont-email.me> <11amf6v$10g9m$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!peer02.iad!feed-me.highwinds-media.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!2.eu.feeder.erje.net!feeder.erje.net!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: Tue, 13 Oct 2026 16:46:21 -0700
Organization: A noiseless patient Spider
Lines: 218
Message-ID: <11amfsg$10sng$1@dont-email.me>
References: <118f4vv$3plsv$1@dont-email.me> <11ag8ue$2nvjl$1@dont-email.me>
 <11alo51$nmur$1@dont-email.me> <11am17q$rl8q$1@dont-email.me>
 <11amf6v$10g9m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Oct 2026 23:46:25 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1078000"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+i0b1XJCCkjiJizXTRegdAHmhU3YuWiXA="; posting-host="094496f6b743c51c3f22a7000b0b8b16"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:208QTj6XggOg7b7GyFD7/ty3spo= sha256:Q23ZG65lz1FjIiKOfDsZlbbanUauBEC0j0aG9FCnTac=
	sha1:WWKVsU+sX1xD1BP81kApFhlg6Z8= sha256:YfztLMDX785AB5y1EEsV2VQdnonMY9ByxvdTG/lIu4U=
In-Reply-To: <11amf6v$10g9m$1@dont-email.me>
Content-Language: en-US
X-Received-Bytes: 7568