Skip to content

Commit db5949f

Browse files
authored
Merge pull request #11193 from Octachron/concurrency_alerts_part_one
Concurrency safety documentation, part one: concurrency unsafe types
2 parents f8d64f3 + 7c79659 commit db5949f

11 files changed

Lines changed: 107 additions & 9 deletions

File tree

stdlib/buffer.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@
3030
3131
*)
3232

33+
(** {b Unsynchronized accesses} *)
34+
35+
[@@@alert unsynchronized_access
36+
"Unsynchronized accesses to buffers are a programming error."
37+
]
38+
39+
(**
40+
Unsynchronized accesses to a buffer may lead to an invalid buffer state.
41+
Thus, concurrent accesses to a buffer must be synchronized (for instance
42+
with a {!Mutex.t}).
43+
*)
44+
3345
type t
3446
(** The abstract type of buffers. *)
3547

stdlib/ephemeron.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@
6565
@since 4.03
6666
*)
6767

68+
(** {b Unsynchronized accesses} *)
69+
70+
[@@@alert unsynchronized_access
71+
"Unsynchronized accesses to weak hash tables are a programming error."
72+
]
73+
74+
(**
75+
Unsynchronized accesses to a weak hash table may lead to an invalid
76+
weak hash table state. Thus, concurrent accesses to a buffer must be
77+
synchronized (for instance with a {!Mutex.t}).
78+
*)
79+
6880
module type S = sig
6981
(** Propose the same interface as usual hash table. However since
7082
the bindings are weak, even if [mem h k] is true, a subsequent

stdlib/hashtbl.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@
4141
See {{!examples} the examples section}.
4242
*)
4343

44+
(** {b Unsynchronized accesses} *)
45+
46+
[@@@alert unsynchronized_access
47+
"Unsynchronized accesses to hash tables are a programming error."
48+
]
49+
50+
(**
51+
Unsynchronized accesses to a hash table may lead to an invalid hash table
52+
state. Thus, concurrent accesses to a hash tables must be synchronized
53+
(for instance with a {!Mutex.t}).
54+
*)
55+
4456

4557
(** {1 Generic interface} *)
4658

stdlib/moreLabels.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ module Hashtbl : sig
5858
See {{!examples} the examples section}.
5959
*)
6060

61+
(** {b Unsynchronized accesses} *)
62+
63+
[@@@alert unsynchronized_access
64+
"Unsynchronized accesses to hash tables are a programming error."
65+
]
66+
67+
(**
68+
Unsynchronized accesses to a hash table may lead to an invalid hash table
69+
state. Thus, concurrent accesses to a hash tables must be synchronized
70+
(for instance with a {!Mutex.t}).
71+
*)
72+
6173

6274
(** {1 Generic interface} *)
6375

stdlib/oo.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515

1616
(** Operations on objects *)
1717

18-
val copy : (< .. > as 'a) -> 'a
1918
(** [Oo.copy o] returns a copy of object [o], that is a fresh
2019
object with the same methods and instance variables as [o]. *)
20+
val copy : (< .. > as 'a) -> 'a
21+
[@@alert unsynchronized_access
22+
"Unsynchronized accesses to mutable objects are a programming error."
23+
]
2124

2225
external id : < .. > -> int = "%field1"
2326
(** Return an integer identifying this object, unique for

stdlib/queue.mli

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717
1818
This module implements queues (FIFOs), with in-place modification.
1919
See {{!examples} the example section} below.
20+
*)
21+
22+
(** {b Unsynchronized accesses} *)
23+
24+
[@@@alert unsynchronized_access
25+
"Unsynchronized accesses to queues are a programming error."
26+
]
2027

21-
{b Warning} This module is not thread-safe: each {!Queue.t} value
22-
must be protected from concurrent access (e.g. with a [Mutex.t]).
23-
Failure to do so can lead to a crash.
28+
(**
29+
Unsynchronized accesses to a queue may lead to an invalid queue state.
30+
Thus, concurrent accesses to queues must be synchronized (for instance
31+
with a {!Mutex.t}).
2432
*)
2533

2634
type !'a t

stdlib/scanf.mli

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,17 @@
8181
facility is fully type-checked at compile time.
8282
*)
8383

84-
(** {2 Note on concurrent use} *)
84+
(** {b Unsynchronized accesses} *)
8585

86-
(** Since values of type {!Scanning.in_channel} contain inner mutable states,
87-
they are not safe to use concurrently without external synchronization.
86+
[@@@alert unsynchronized_access
87+
"Unsynchronized accesses to Scanning.in_channel are a programming error."
88+
]
89+
90+
(**
91+
Unsynchronized accesses to a {!Scanning.in_channel} may lead to an
92+
invalid {!Scanning.in_channel} state. Thus, concurrent accesses
93+
to {!Scanning.in_channel}s must be synchronized (for instance with
94+
a {!Mutex.t}).
8895
*)
8996

9097
(** {1 Formatted input channel} *)

stdlib/stack.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
This module implements stacks (LIFOs), with in-place modification.
1919
*)
2020

21+
(** {b Unsynchronized accesses} *)
22+
23+
[@@@alert unsynchronized_accesses
24+
"Unsynchronized accesses to stacks are a programming error."
25+
]
26+
27+
(**
28+
Unsynchronized accesses to a stack may lead to an invalid queue state.
29+
Thus, concurrent accesses to stacks must be synchronized (for instance
30+
with a {!Mutex.t}).
31+
*)
32+
2133
type !'a t
2234
(** The type of stacks containing elements of type ['a]. *)
2335

stdlib/templates/hashtbl.template.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@
4141
See {{!examples} the examples section}.
4242
*)
4343

44+
(** {b Unsynchronized accesses} *)
45+
46+
[@@@alert unsynchronized_access
47+
"Unsynchronized accesses to hash tables are a programming error."
48+
]
49+
50+
(**
51+
Unsynchronized accesses to a hash table may lead to an invalid hash table
52+
state. Thus, concurrent accesses to a hash tables must be synchronized
53+
(for instance with a {!Mutex.t}).
54+
*)
55+
4456

4557
(** {1 Generic interface} *)
4658

stdlib/weak.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ val blit : 'a t -> int -> 'a t -> int -> int -> unit
114114
the values and give the same result as with the values themselves.
115115
*)
116116

117+
(** {b Unsynchronized accesses}
118+
119+
Unsynchronized accesses to weak hash sets are a programming error.
120+
Unsynchronized accesses to a weak hash set may lead to an invalid weak hash
121+
set state. Thus, concurrent accesses to weak hash sets must be synchronized
122+
(for instance with a {!Mutex.t}).
123+
*)
124+
117125
module type S = sig
118126
type data
119127
(** The type of the elements stored in the table. *)

0 commit comments

Comments
 (0)