Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" Newsgroups: comp.arch Subject: Re: Strange asm generated by GCC... Date: Mon, 23 Dec 2024 17:53:28 -0800 Organization: A noiseless patient Spider Lines: 28 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 24 Dec 2024 02:53:28 +0100 (CET) Injection-Info: dont-email.me; posting-host="d7ce48cf38462b28073ed26d9c338b5a"; logging-data="1572535"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fxOxTkjeX7LwqYjL4vTglmvqUHbDxAP0=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:1kUzkzdgBgGWIkWZ66C8ngJVT1o= In-Reply-To: Content-Language: en-US Bytes: 2288 On 12/23/2024 5:16 PM, jseigh wrote: > On 12/23/24 16:20, Chris M. Thomasson wrote: > >> >> Wrt a traditional lock-free stack, I think the store can use relaxed >> for the success path of a CAS. > > For pushing onto a stack, you want release.  For popping from a stack > you want acquire. Right. We want the release right before we atomically introduce the node into the stack. For the pop, we can load the head and do an acquire wrt the loop. load the next node in said loop, do the CAS. The success part of the CAS can be a relaxed, the failure would need an another acquire? > > You are probably ok using relaxed loading the old value.  It's not > real clear how aggressive the compiler is allowed to be with relaxed > loads and stores.  To be super safe, you might want to add acquire > to all your cas loops. > > I would just stick with the compare_exchange w/ 1 memory order > parameter.  The success/fail form is just confusing, the fail > parameter doesn't do anything. > >