1Atomic(3) OCaml library Atomic(3)
2
3
4
6 Atomic - Atomic references.
7
9 Module Atomic
10
12 Module Atomic
13 : sig end
14
15
16 Atomic references.
17
18 See 'Memory model: The hard bits' chapter in the manual.
19
20
21 Since 4.12
22
23
24
25
26
27 type 'a t
28
29
30 An atomic (mutable) reference to a value of type 'a .
31
32
33
34 val make : 'a -> 'a t
35
36 Create an atomic reference.
37
38
39
40 val get : 'a t -> 'a
41
42 Get the current value of the atomic reference.
43
44
45
46 val set : 'a t -> 'a -> unit
47
48 Set a new value for the atomic reference.
49
50
51
52 val exchange : 'a t -> 'a -> 'a
53
54 Set a new value for the atomic reference, and return the current value.
55
56
57
58 val compare_and_set : 'a t -> 'a -> 'a -> bool
59
60
61 compare_and_set r seen v sets the new value of r to v only if its cur‐
62 rent value is physically equal to seen -- the comparison and the set
63 occur atomically. Returns true if the comparison succeeded (so the set
64 happened) and false otherwise.
65
66
67
68 val fetch_and_add : int t -> int -> int
69
70
71 fetch_and_add r n atomically increments the value of r by n , and re‐
72 turns the current value (before the increment).
73
74
75
76 val incr : int t -> unit
77
78
79 incr r atomically increments the value of r by 1 .
80
81
82
83 val decr : int t -> unit
84
85
86 decr r atomically decrements the value of r by 1 .
87
88
89
90
91
92OCamldoc 2023-07-20 Atomic(3)