Queue.add is not thread/signal safe #5309
Original bug ID: 5309
If an exception is raised in a signal after the first line of Queue.add (i.e. increasing the length counter of the queue), the queue invariants are broken and bad things can happen (segfault...).
In the additional information, I provide a new "add" function that should be thread/signal safe.
let add x q =
The text was updated successfully, but these errors were encountered:
Comment author: @gasche
To sum up yesterday's discussion: the OCaml library is not guaranteed to be signal-safe, or rather, it is voluntarily guaranteed not to be signal-safe. Users should acknowledge that using mutable data structures expose them to signal hazards, and stick to immutable data structures or use different, specialized signal-hardened libraries.
That said, this specific patch is relatively harmless -- in particular, it does not impact clarity and readability -- and Fabrice may include it.
As a personal note: we may also write
begin if q.length = 1 then
to avoid duplicating the common length-extension logic. Of course, it's only a dispensable detail.