Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" 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: References: 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: 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!