Standard C Library Functions membar_ops(3C)
NAME
membar_ops, membar_enter, membar_exit, membar_producer,
membar_consumer - memory access synchronization barrier
operationsSYNOPSIS
#include
void membar_enter(void);
void membar_exit(void);
void membar_producer(void);
void membar_consumer(void);
DESCRIPTION
The membar_enter() function is a generic memory barrier used
during lock entry. It is placed after the memory operation that acquires the lock to guarantee that the lock protects its data. No stores from after the memory barrier will reach visibility and no loads from after the barrier will beresolved before the lock acquisition reaches global visibil-
ity.The membar_exit() function is a generic memory barrier used
during lock exit. It is placed before the memory opera-
tion that releases the lock to guarantee that the lock pro-
tects its data. All loads and stores issued before the bar-
rier will be resolved before the subsequent lock update reaches visibility.The membar_enter() and membar_exit() functions are used
together to allow regions of code to be in relaxed storeorder and then ensure that the load or store order is main-
tained at a higher level. They are useful in the implementa-
tion of mutex exclusion locks.The membar_producer() function arranges for all stores
issued before this point in the code to reach global visi-
bility before any stores that follow. This is useful in pro-
ducer modules that update a data item, then set a flag that it is available. The memory barrier guarantees that the available flag is not visible earlier than the updated data, thereby imposing store ordering.SunOS 5.11 Last change: 14 Feb 2005 1
Standard C Library Functions membar_ops(3C)
The membar_consumer() function arranges for all loads issued
before this point in the code to be completed before any subsequent loads. This is useful in consumer modules that check if data is available and read the data. The memory barrier guarantees that the data is not sampled until afterthe available flag has been seen, thereby imposing load ord-
ering.RETURN VALUES
No values are returned.ERRORS
No errors are defined.ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| Interface Stability | Committed ||_____________________________|_____________________________|
| MT-Level | MT-Safe |
|_____________________________|_____________________________|
SEE ALSO
atomic_add(3C), atomic_and(3C), atomic_bits(3C),
atomic_cas(3C), atomic_dec(3C), atomic_inc(3C),
atomic_ops(3C), atomic_or(3C), atomic_swap(3C), attri-
butes(5), atomic_ops(9F)
NOTESAtomic instructions (see atomic_ops(3C)) ensure global visi-
bility of atomically-modified variables on completion. In a
relaxed store order system, this does not guarantee that the visibility of other variables will be synchronized with thecompletion of the atomic instruction. If such synchroniza-
tion is required, memory barrier instructions must be used.SunOS 5.11 Last change: 14 Feb 2005 2