Version française
Home     About     Download     Resources     Contact us    
Browse thread
Problems spawning threads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Edgar Friendly <thelema314@g...>
Subject: Problems spawning threads
I've gone over the Computer Language Benchmarks Game[1] problems, and I
can't figure out how help the administrators of this problem to get the
OCaml code for the thread-ring benchmark (contributed by Charles Martin)
to work on their computer.

Here's the code:

let size = 503

let n = int_of_string Sys.argv.(1)

let run id ichan ochan =
  let rec loop () =
    let token = Event.sync (Event.receive ichan) in
    if token = n then (print_int id; print_newline (); exit 0)
    else (Event.sync (Event.send ochan (token + 1)); loop ())
  in Thread.create loop ()

let () =
  let channels =
    Array.init size
      (fun _ -> Event.new_channel ()) in
  let threads =
    Array.init size
      (fun i -> run (i + 1) channels.(i) channels.((i + 1) mod size)) in
  Event.sync (Event.send channels.(0) 0);
  Thread.join threads.(0)


Here's the compilation and execution:

~/tmp/testzone $ /usr/bin/ocamlopt -thread -noassert -unsafe
-I /usr/lib/ocaml/contrib -ccopt -O3 -ccopt -fomit-frame-pointer
-ccopt -march=pentium4 unix.cmxa threads.cmxa threadring.ml -o
threadring.ocaml_run

~/tmp/testzone $ ./threadring.ocaml_run 100
Fatal error: exception Sys_error("Thread.create: Cannot
allocate memory")


The code runs fine when compiled with ocamlc -vmthread ....  It works
fine on my Athlon with the same compilation options (except for
-march=athlon-tbird).

Interestingly enough, the administrator reports that the code works with
size=16, but fails for size=17.  Any ideas what's going on or how to fix
it?  Hopefully I'll have some confirmation soon that the (probably
useless) ccopts and other optimization options don't affect the error.

We also checked ulimit settings - his max user processes and stack size
are both higher than mine. (-u 4095, -s 160000k)  Any other ulimit
options that could interfere?  Last piece of information: his box runs
Gentoo Linux.

E.