struct Syn::Core::AtomicLock

Overview

Similar to Atomic::Flag but adds memory barriers (fences) in addition to the atomic instructions, and relies on the acquire/release memory ordering that should be suitable for locks.

Basically, the atomic instructions tell the CPU to use an atomic operand on the CPU and usually their memory ordering also serves as hints to the compiler (here LLVM) to not reorder instructions across the atomic. The fences add another level of protection against weak CPU architectures (such as ARM), telling them to not reorder instructions across the fences at runtime.

The memory fences should be noop and optimized away on non weak CPU architectures such as x86/64.

Defined in:

core/atomic_lock.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def acquire? : Bool #

Acquires the lock. The operation is atomic, and any operation that happens after the acquire won't be reordered before the acquire, either during compilation or live at runtime on weak CPU architectures.


[View source]
def release : Nil #

Releases the lock. The operation is atomic, and any operation that happens before the release won't be reordered after the release, either during compilation or live at runtime on weak CPU architectures.


[View source]