You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 5309 Reporter:@lefessan Assigned to:@lefessan Status: closed (set by @xavierleroy on 2015-12-11T18:04:34Z) Resolution: fixed Priority: normal Severity: minor Platform: all OS: all OS Version: all Version: 3.12.1+dev Fixed in version: 3.13.0+dev Category: ~DO NOT USE (was: OCaml general) Monitored by: khooyp
Bug description
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.
Additional information
let add x q =
if q.length = 0 then
let rec cell = {
content = x;
next = cell
} in
q.length <- q.length + 1;
q.tail <- cell
else
let tail = q.tail in
let head = tail.next in
let cell = {
content = x;
next = head
} in
q.length <- q.length + 1;
tail.next <- cell;
q.tail <- cell
The text was updated successfully, but these errors were encountered:
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
..
else
..
end;
q.length <- q.length + 1
to avoid duplicating the common length-extension logic. Of course, it's only a dispensable detail.
Original bug ID: 5309
Reporter: @lefessan
Assigned to: @lefessan
Status: closed (set by @xavierleroy on 2015-12-11T18:04:34Z)
Resolution: fixed
Priority: normal
Severity: minor
Platform: all
OS: all
OS Version: all
Version: 3.12.1+dev
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: khooyp
Bug description
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.
Additional information
let add x q =
if q.length = 0 then
let rec cell = {
content = x;
next = cell
} in
q.length <- q.length + 1;
q.tail <- cell
else
let tail = q.tail in
let head = tail.next in
let cell = {
content = x;
next = head
} in
q.length <- q.length + 1;
tail.next <- cell;
q.tail <- cell
The text was updated successfully, but these errors were encountered: