Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 35 |
Nodes: | 6 (1 / 5) |
Uptime: | 19:11:02 |
Calls: | 321 |
Calls today: | 1 |
Files: | 957 |
Messages: | 82,383 |
On 12/22/2024 7:49 PM, Chris M. Thomasson wrote:
On 12/21/2024 2:37 AM, aph@littlepinkcloud.invalid wrote:
jseigh <jseigh_es00@xemaps.com> wrote:
I don't see anything that forces a store memory barrier
on all the fail paths. I could be missing something.
Why would there be one? If the store does not take place, there's no
need for a memory barrier because there's no store for anyone to
synchronize with. The only effect of a failed weak CAS is a load. If
you really need a store on failure because of its side effect you can
always add one.
Iirc, the membars for the success and failure can be "useful" for
popping from a lock-free stack. Wrt the C++ API the CAS can give you the
updated value on a failure. So, there is a load. Depending on what you
are doing, it might require an acquire.
Loading the head of the lock-free stack would be an acquire at the start
of the CAS loop. The CAS can use relaxed for the success and an acquire
for the failure.
I don't see anything that forces a store memory barrier
Wrt a traditional lock-free stack, I think the store can use relaxed for
the success path of a CAS.
On 12/23/2024 5:53 PM, Chris M. Thomasson wrote:
On 12/23/2024 5:16 PM, jseigh wrote:
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.
Actually, can the acquire be relaxed into a consume?