Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytecode threads in Ocaml-2.04 / 2.02 / 1.05 #2343

Closed
vicuna opened this issue Dec 21, 1999 · 2 comments
Closed

bytecode threads in Ocaml-2.04 / 2.02 / 1.05 #2343

vicuna opened this issue Dec 21, 1999 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 21, 1999

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

@vicuna
Copy link
Author

vicuna commented Dec 21, 1999

Comment author: administrator

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

@vicuna
Copy link
Author

vicuna commented Dec 21, 1999

Comment author: administrator

Fixed in 3.00

@vicuna vicuna closed this as completed Dec 21, 1999
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant