English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
[Caml-list] C interface, threads and ocaml callbacks
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-03-03 (23:15)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: [Caml-list] C interface, threads and ocaml callbacks

I'm trying to do a binding from ocaml to a C function f which may spawn 
threads when invoked. These threads may concurrently try to invoke 
ocaml registrated callbacks. However when f returns I'm guaranteed that 
all spawn threads have terminated.

I'm aware of these messages [1] but I'm not sure I really got the 
point. My understanding is that two threads should not callback into 
caml at the same time and that in order to do so, the following should 
be done. If anyone could comment/correct.

1. Link and compile everything used by the program invoking the stub to 
with the option -thread.

2. In the stub to function f, bracket the call to f with 

CAMLprim value f_stub (value v)
{ /* convert arguments */
     res = f(arg)  /* In this function threads will try to concurently 
access ocaml */
   /* convert result of f() */

3. Around any call from f back into caml, bracket code with 

/* convert parameters */
res = callback(closure,arg)
/* convert result */

4. The user of the stub should not use caml threads in the ocaml code 
(at all or only in the callbacks ?) and not link against caml threading 
libraries (even if I tell f() to stay single threaded but using the 
same stub code ?).

Thanks for your answers,


P.S. Is that somewhere documented ?


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