Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000015OCamlOCaml generalpublic1999-12-21 16:001999-12-21 16:07
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000015: bytecode threads in Ocaml-2.04 / 2.02 / 1.05
DescriptionFull_Name: Pawel Wojciechowski
Version: 2.04
OS:
Submission from: estephe.inria.fr (128.93.11.95)
Submitted by: xleroy


Hello!

Just to ask if all is fine with bytecode threads in OCaml version 2.04?

In the program below I create two threads, one is doing some computation
(counter), second thread is executing a wait function. In the main program
I wait until the second thread terminates and then I print a current state
of the computation being done by the first thread. I checked three kinds
of wait function: a blocking input from console, a non-blocking low-level
input from ThreadUnix module and a simple recursive loop.

For each function "wait":

In Ocaml 1.05 the counter thread is never blocked

In Ocaml 2.02 the counter thread is never blocked but.. if we change
         the program so as we don't create a separate thread for a function
         wait then if wait executes read_line() or read() the program prints
         0 as a result (thus it seems like I/O operation blocks the thread
         counter?)

In Ocaml 2.04 The program behaves abnormally and suspends execution in
         every case.

I installed Ocaml* on i686 Linux and I'm compiling the program using:

ocamlc -thread -custom unix.cma threads.cma -cclib -lunix -cclib -lthreads
$1 -o $2


best regards, -
Pawel Wojciechowski


open Unix
open ThreadUnix

let res = ref 0
let s = Mutex.create()

let rec counter i =
  Mutex.lock s; res := i; Mutex.unlock s;
  counter (i + 1)

(*
  let wait () = let _ = read_line () in ()
*)
(*
  let wait () =
    let line = String.create 60 in
    let len = read stdin line 0 60 in
    print_string (String.sub line 0 len)
*)
  let wait () =
    let rec loop i =
      if i < 3000000 then loop (i + 1) else i
    in loop 0

(* VERSION 1: two threads *)

let main () =
  let _ = Thread.create counter 0 in
  let t = Thread.create wait () in
  Thread.join t;
  Mutex.lock s; print_int !res; Mutex.unlock s

let _ = main ()



(* VERSION 2: one thread *)

let main () =
  let _ = Thread.create counter 0 in
  wait();
  Mutex.lock s; print_int !res; Mutex.unlock s

let _ = main ()



-------------------------------------------------------------------
Pawel T. Wojciechowski, Computer Lab., University of Cambridge
www.cl.cam.ac.uk/users/ptw20, office +44(1223 )334 602, fax 335 908



TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000289)
administrator (administrator)
1999-12-21 16:05

> Just to ask if all is fine with bytecode threads in OCaml version 2.04?

I thought so :-) But you've found an interesting bug. Basically, the
timer-based
preemption of long-running threads (such as "counter" in your example) stopped
working when I revised the handling of signals in OCaml 2.02. The problem
didn't show up on my tests because all their threads perform enough
inter-thread
communications to still work under cooperative (non-preemptive) scheduling.

This will be fixed in release 3.00. If you're interested, I'll send you a
patch
against 2.99.

Thanks for your bug report,

- Xavier Leroy
(0000290)
administrator (administrator)
1999-12-21 16:07

Fixed in 3.00

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker