Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] "noalloc" + enter/leave blocking section - safe?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] "noalloc" + enter/leave blocking section - safe?
On Mon, 02 Aug 2004, Markus Mottl wrote:
> one important question: is it safe to use "noalloc" with
> C-functions that contain calls to "caml_enter_blocking_section" and
> "caml_leave_blocking_section" to allow other POSIX-treads?

Ok, after having done some experiments on my own now, it seems that this
is _not_ safe.  Here is a small example that demonstrates this:

file: foo.ml
---------------------------------------------------------------------------
external foo : 'a -> unit = "foo_stub" "noalloc"

let thread () =
  let ar = Array.init 1 (fun _ -> "") in
  foo ();
  let ar = Array.init 1 (fun _ -> "") in
  ()

let () =
  let n = 10 in
  let ar = Array.create n () in
  let tids = Array.map (Thread.create thread) ar in
  Array.iter Thread.join tids
---------------------------------------------------------------------------


file: foo_stubs.c
---------------------------------------------------------------------------
#include <caml/mlvalues.h>
#include <caml/signals.h>

CAMLprim value foo_stub(value v) {
  caml_enter_blocking_section();
    int i;
    for (i = 0; i < 100000000; i++);
  caml_leave_blocking_section();
  return Val_unit;
}
---------------------------------------------------------------------------

Compiling and linking the above example to native code (i.e. with
POSIX-threads) and running it will almost immediately produce a segfault
on my machine.  Removing "noalloc" solves this problem.

Could the documentation on the C-interface please be updated with a
small section on the correct use of "noalloc"?  It's not documented at
all right now!  (This also closes bug report #3019, I guess).

Regards,
Markus

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners