Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Problems spawning threads
@ 2007-12-18  5:18 Edgar Friendly
  2007-12-18  5:23 ` Edgar Friendly
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Edgar Friendly @ 2007-12-18  5:18 UTC (permalink / raw)
  To: caml-list

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-12-18 17:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-18  5:18 Problems spawning threads Edgar Friendly
2007-12-18  5:23 ` Edgar Friendly
2007-12-18  8:03 ` [Caml-list] " Michael Wohlwend
2007-12-18 10:59 ` Zheng Li
2007-12-18 15:57   ` [Caml-list] " Edgar Friendly
2007-12-18 17:05     ` Zheng Li
2007-12-18 17:40       ` [Caml-list] " Edgar Friendly
2007-12-18 16:22 ` [Caml-list] " Xavier Leroy
2007-12-18 17:04 ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox