Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003236OCamlOCaml generalpublic2004-10-25 22:062014-05-25 20:20
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version 
Target Version4.02.0+devFixed in Version 
Summary0003236: Queue+Threads+Cygwin native causes crash
DescriptionFull_Name: Matthew W. Boyd
Version: 3.08.1
OS: Windows/Cygwin
Submission from: outbound.mlog.com (216.127.133.66)


The following application will cause a core dump when compiled in the following
way (Under Cygwin):

ocamlopt -thread -o qthr unix.cmxa threads.cmxa qthr.ml

(* ---------------------------------------- *)
open Unix
open Printf
open Pervasives

let q = Queue.create ()

let try_take () =
  try Queue.take q
  with Queue.Empty -> 0

let rec randomaction n =
  let () =
    match Random.int 2 with
    | 0 -> printf "Taking: %d\n" (try_take ())
    | _ -> printf "Adding\n"; Queue.add n q
  in
  flush stdout;
  randomaction (n+1)

let v =
  let a = Array.create 10 (Thread.self()) in
  for i = 0 to 9 do
    a.(i) <- Thread.create randomaction i
  done;
  a
;;

let hent = Unix.gethostbyname "localhost" in
for i = 0 to 9 do
  Thread.join v.(i)
done
;;
(* ---------------------------------------- *)

I noticed this while I was attempting to use a shared queue with multiple
threads.

In this sample application, the program will not crash unless I call
Unix.gethostbyname.

I also noticed that if I call Unix.gethostbyname after unblocking Sys.sigint,
the signal will be blocked again after the call to Unix.gethostbyname; however,
if I
unblock the signal after calling gethostbyname, it will remain unblocked.

I also noticed that I can prevent the segmentation fault by wrapping any Queue
function calls with Mutex locks.


TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0003092)
administrator (administrator)
2005-02-02 16:56

Unlocked concurrent accesses to Queue are inherently unsafe. Still, can't
reproduce crash under Linux. Can reproduce it under Cygwin with and without
the
gethostbyname. gdb gives no useful context. No can do.
(0008054)
doligez (administrator)
2012-09-11 09:35

Just looking at the code of Queue.take, it's obvious that concurrent access to a queue can cause a crash.
This should be documented.

We also need to investigate the interference between Unix.gethostbyname and signals under Cygwin.
(0009843)
doligez (administrator)
2013-07-24 10:54

Added a warning at the top of queue.mli (branch 4.01, rev 13929).

Still need to investigate gethostbyname vs sigint.
(0009849)
frisch (developer)
2013-07-24 13:00

> Added a warning at the top of queue.mli (branch 4.01, rev 13929).

I'm all in favor of a more explicit documentation about thread-safety, but maybe thread-unsafety should be stressed at a higher level (there are much more thread-unsafe modules: Lazy, Hashtbl, Dynlink, etc...)

- Issue History
Date Modified Username Field Change
2005-11-18 10:14 administrator New Issue
2012-07-11 17:32 doligez Target Version => 4.01.0+dev
2012-07-11 17:32 doligez Description Updated View Revisions
2012-07-31 13:37 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-11 09:35 doligez Note Added: 0008054
2012-09-11 09:35 doligez Target Version 4.00.1+dev => 4.00.2+dev
2012-09-11 09:35 doligez Resolution unable to reproduce => open
2013-07-02 14:38 doligez Target Version 4.00.2+dev => 4.01.0+dev
2013-07-24 10:54 doligez Note Added: 0009843
2013-07-24 10:54 doligez Target Version 4.01.0+dev => 4.01.1+dev
2013-07-24 13:00 frisch Note Added: 0009849
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker