Deutsch   English   Français   Italiano  
<vt52qf$nrf$3@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups: comp.arch
Subject: Re: Futex Stack...
Date: Tue, 8 Apr 2025 23:07:11 -0700
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <vt52qf$nrf$3@dont-email.me>
References: <vrtkv8$2pae3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 09 Apr 2025 08:07:12 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d6b678eb7e1d3f498ba97e7a21a9aa05";
	logging-data="24431"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19soKqqSFBDpnRJOCdg9v+yl4UZcEg8r9U="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:mfUWd2wMqpkqDMLsTDILMEHWopc=
Content-Language: en-US
In-Reply-To: <vrtkv8$2pae3$1@dont-email.me>
Bytes: 2085

On 3/25/2025 12:11 AM, Chris M. Thomasson wrote:
> This is a little C++20 test using a futex to allow one to wait on a 
> lock-free stack. The main stack logic is in struct ct_stack. Well, can 
> you get to compile and run? Thanks... There is no need for DWCAS here. 
> It uses just XCHG and CMPXCHG.
> 
> 
> My code:
> ______________________________________

[...]

To tidy things up a little, the flush_wait can look like this:
____________________
ct_node*
flush_wait()
{
     ct_node* head = m_head.exchange(nullptr, std::memory_order_acquire);

     while (! head || head == CT_WAIT)
     {
         // slow path...
         head = m_head.exchange(CT_WAIT, std::memory_order_acquire);

         if (! head || head == CT_WAIT)
         {
             m_head.wait(CT_WAIT, std::memory_order_relaxed);
         }
     }

     assert(head && head != CT_WAIT);

     return head;
}

____________________

Also, I made a spelling error wrt:

     unsigned long g_ct_work_alloations = 0;
     unsigned long g_ct_work_dealloations = 0;

grrrrr!