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