2 ms·
Actually acquire/release barriers or operations are not enough. I'm pretty sure you also need a #StoreLoad for example between Step 1 and Step 2 in the lock alg
by gpderetta 3y ago
Actually acquire/release barriers or operations are not enough. I'm pretty sure you also need a #StoreLoad for example between Step 1 and Step 2 in the lock algorithm, to prevent the loads from other thread state in step 2 to be reordered before the stores to the own thread state in step 1.
Generally #StoreLoad is required when you need bidirectional synchronization between two or more threads.
Re atomics, I think the algorithm still requires word sized operations to be atomic, but I think that was considered a given. What the algorithm doesn't require is atomic load/stores (or more complex RMW) across more than one word.
- Vecr 3y agoCould you implement it using AtomicUsize (using only relaxed operations) in Rust? With AtomicUsize representing the words. You aren't allowed to put pointers in those.
- gpderetta 3y agoIf atomicusize is sequentially consistent, then yes.
- exDM69 3y agoNo, it can not use relaxed memory ordering. Looking at disassembly of relaxed atomic operations, they are just normal loads and stores with no memory barriers or special instructions. That is not enough to make this algorithm guard a critical section.
- gpderetta 3y agoForget about the last bit re atomics, apparently the algorithm is indeed resistant to teared writes.