@@ -55,17 +55,31 @@ module Awaitable : sig
5555
5656 val signal : 'a t -> unit
5757 (* * [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. *)
5967
6068 val broadcast : 'a t -> unit
6169 (* * [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. *)
6377
6478 val await : 'a t -> 'a -> unit
6579 (* * [await awaitable before] suspends the current fiber until the awaitable is
6680 explicitly {!signal}ed and has a value other than [before].
6781
68- ⚠️ This operation is subject to
82+ ⚠️ This operation is subject to the
6983 {{:https://en.wikipedia.org/wiki/ABA_problem} ABA} problems. An [await]
7084 for value other than [A] may not return after the awaitable is signaled
7185 while having the value [B], because at a later point the awaitable has
0 commit comments