1membar_ops(3C) Standard C Library Functions membar_ops(3C)
2
3
4
6 membar_ops, membar_enter, membar_exit, membar_producer, membar_consumer
7 - memory access synchronization barrier operations
8
10 #include <atomic.h>
11
12 void membar_enter(void);
13
14
15 void membar_exit(void);
16
17
18 void membar_producer(void);
19
20
21 void membar_consumer(void);
22
23
25 The membar_enter() function is a generic memory barrier used during
26 lock entry. It is placed after the memory operation that acquires the
27 lock to guarantee that the lock protects its data. No stores from after
28 the memory barrier will reach visibility and no loads from after the
29 barrier will be resolved before the lock acquisition reaches global
30 visibility.
31
32
33 The membar_exit() function is a generic memory barrier used during lock
34 exit. It is placed before the memory operation that releases the
35 lock to guarantee that the lock protects its data. All loads and stores
36 issued before the barrier will be resolved before the subsequent
37 lock update reaches visibility.
38
39
40 The membar_enter() and membar_exit() functions are used together to
41 allow regions of code to be in relaxed store order and then ensure that
42 the load or store order is maintained at a higher level. They are use‐
43 ful in the implementation of mutex exclusion locks.
44
45
46 The membar_producer() function arranges for all stores issued before
47 this point in the code to reach global visibility before any stores
48 that follow. This is useful in producer modules that update a data
49 item, then set a flag that it is available. The memory barrier guaran‐
50 tees that the available flag is not visible earlier than the updated
51 data, thereby imposing store ordering.
52
53
54 The membar_consumer() function arranges for all loads issued before
55 this point in the code to be completed before any subsequent loads.
56 This is useful in consumer modules that check if data is available and
57 read the data. The memory barrier guarantees that the data is not sam‐
58 pled until after the available flag has been seen, thereby imposing
59 load ordering.
60
62 No values are returned.
63
65 No errors are defined.
66
68 See attributes(5) for descriptions of the following attributes:
69
70
71
72
73 ┌─────────────────────────────┬─────────────────────────────┐
74 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
75 ├─────────────────────────────┼─────────────────────────────┤
76 │Interface Stability │Stable │
77 ├─────────────────────────────┼─────────────────────────────┤
78 │MT-Level │MT-Safe │
79 └─────────────────────────────┴─────────────────────────────┘
80
82 atomic_add(3C), atomic_and(3C), atomic_bits(3C), atomic_cas(3C),
83 atomic_dec(3C), atomic_inc(3C), atomic_ops(3C), atomic_or(3C),
84 atomic_swap(3C), attributes(5), atomic_ops(9F)
85
87 Atomic instructions (see atomic_ops(3C)) ensure global visibility of
88 atomically-modified variables on completion. In a relaxed store order
89 system, this does not guarantee that the visibility of other variables
90 will be synchronized with the completion of the atomic instruction. If
91 such synchronization is required, memory barrier instructions must be
92 used.
93
94
95
96SunOS 5.11 14 Feb 2005 membar_ops(3C)