5.12.1.2
Release-Acquire Ordering
If an atomic store in thread A is tagged
memory_order_release
and an atomic load in thread B
from the same variable is tagged
memory_order_acquire
, all memory writes (non-atomic and
relaxed atomic) that
happened-before the atomic store from the point of view of thread A,
become
visible side-effects in thread B. That is, once the atomic load is completed, thread B is
guaranteed to see everything thread A wrote to memory.
The synchronization is established only between the threads
releasing and
acquiring the same
atomic variable. Other threads can see a different order of memory accesses than either or both
of the synchronized threads.
5.12.1.3
Sequentially Consistent Ordering
Atomic operations tagged
memory_order_seq_cst
order memory the same way as release/
acquire ordering (everything that happened-before a store operation in one thread becomes a
visible side effect in the thread that performed the load) and also establish a single total
modification order of all atomic operations that are so tagged. Sequential ordering may be
necessary for multiple producer-multiple consumer situations, where all consumers must
observe the actions of all producers occurring in the same order.
Note: as soon as an atomic operation that does not use a memory order of
memory_order_seq_cst
is encountered, the sequential consistency is lost.
5.12.2
Memory Scope
The enumerated type
memory_scope
specifies whether the memory ordering constraints given
by
memory_order
apply to threads within a SIMD-group, a threadgroup, or threads across
threadgroups of a kernel(s) executing on the device. Its enumerated values are as follows:
enum memory_scope {memory_scope_simdgroup, memory_scope_threadgroup,
memory_scope_device};
The memory scope can be specified when performing atomic operations to
device
memory.
Atomic operations to
threadgroup
memory only guarantee memory ordering in the
threadgroup, not across threadgroups.
5.12.3
Fence Functions
For iOS, the following fence functions are supported.
void atomic_thread_fence(mem_flags flags, memory_order order)
void atomic_thread_fence(mem_flags flags, memory_order order, memory_scope
scope)
atomic_thread_fence
establishes memory synchronization ordering of non-atomic and
relaxed atomic accesses, as instructed by
order
, without an associated atomic function. For
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page
of
138
174