@@ -55,17 +55,31 @@ module Awaitable : sig
55
55
56
56
val signal : 'a t -> unit
57
57
(* * [signal awaitable] tries to wake up one fiber {!await}in on the awaitable
58
- location. *)
58
+ location.
59
+
60
+ 🐌 Generally speaking one should avoid calling [signal] too frequently,
61
+ because the queue of awaiters is stored separately from the awaitable
62
+ location and it takes a bit of effort to locate it. For example, calling
63
+ [signal] every time a value is added to an empty data structure might not
64
+ be optimal. In many cases it is faster to explicitly mark the potential
65
+ presence of awaiters in the data structure and avoid calling [signal] when
66
+ it is definitely known that there are no awaiters. *)
59
67
60
68
val broadcast : 'a t -> unit
61
69
(* * [broadcast awaitable] tries to wake up all fibers {!await}ing on the
62
- awaitable location. *)
70
+ awaitable location.
71
+
72
+ 🐌 The same advice as with {!signal} applies to [broadcast]. In addition,
73
+ it is typically a good idea to avoid potentially waking up large numbers
74
+ of fibers as it can easily lead to the
75
+ {{:https://en.wikipedia.org/wiki/Thundering_herd_problem} thundering herd}
76
+ phenomana. *)
63
77
64
78
val await : 'a t -> 'a -> unit
65
79
(* * [await awaitable before] suspends the current fiber until the awaitable is
66
80
explicitly {!signal}ed and has a value other than [before].
67
81
68
- ⚠️ This operation is subject to
82
+ ⚠️ This operation is subject to the
69
83
{{:https://en.wikipedia.org/wiki/ABA_problem} ABA} problems. An [await]
70
84
for value other than [A] may not return after the awaitable is signaled
71
85
while having the value [B], because at a later point the awaitable has
0 commit comments