Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005309OCamlOCaml generalpublic2011-07-06 11:032012-05-07 15:36
Reporterlefessan 
Assigned Tolefessan 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.12.1+dev 
Target VersionFixed in Version3.13.0+dev 
Summary0005309: Queue.add is not thread/signal safe
DescriptionIf 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 Informationlet 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
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0006041)
mottl (reporter)
2011-07-06 16:02

Nitpicking here:

  q.length <- q.length + 1;

can be replaced by:

    q.length <- 1;

in the first branch.
(0006923)
gasche (developer)
2012-02-15 09:07

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.
(0006936)
lefessan (developer)
2012-02-18 10:36

Fixed in commit r12163 in SVN trunk.

- Issue History
Date Modified Username Field Change
2011-07-06 11:03 lefessan New Issue
2011-07-06 16:02 mottl Note Added: 0006041
2012-02-15 09:07 gasche Note Added: 0006923
2012-02-15 09:07 gasche Assigned To => lefessan
2012-02-15 09:07 gasche Status new => assigned
2012-02-18 10:36 lefessan Note Added: 0006936
2012-02-18 10:36 lefessan Status assigned => resolved
2012-02-18 10:36 lefessan Fixed in Version => 3.13.0+dev
2012-02-18 10:36 lefessan Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker