About spinlock implementation

mogu via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 31 23:44:13 PDT 2016


I found an implementation of spinlock in concurrency.d.
```
static shared struct SpinLock
{
     void lock() { while (!cas(&locked, false, true)) { 
Thread.yield(); } }
     void unlock() { atomicStore!(MemoryOrder.rel)(locked, false); 
}
     bool locked;
}
```
Why atomicStore use MemoryOrder.rel instead of MemoryOrder.raw?


More information about the Digitalmars-d-learn mailing list