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: 15 Reporter: administrator Status: closed Resolution: fixed Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
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:
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
The text was updated successfully, but these errors were encountered:
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.
Original bug ID: 15
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_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
The text was updated successfully, but these errors were encountered: