From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA17062; Thu, 4 Mar 2004 00:15:56 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA16537 for ; Thu, 4 Mar 2004 00:15:55 +0100 (MET) Received: from mail5.bluewin.ch (mail5.bluewin.ch [195.186.1.207]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i23NG1Iq029323 for ; Thu, 4 Mar 2004 00:16:01 +0100 Received: from [10.0.1.2] (62.203.137.191) by mail5.bluewin.ch (Bluewin AG 7.0.024) id 401F78D10053AB7B for caml-list@inria.fr; Wed, 3 Mar 2004 22:50:51 +0000 Mime-Version: 1.0 (Apple Message framework v612) Content-Transfer-Encoding: 7bit Message-Id: <572FE07E-6D65-11D8-B22B-000393DBC266@epfl.ch> Content-Type: text/plain; charset=US-ASCII; format=flowed To: caml-list@inria.fr From: =?ISO-8859-1?Q?Daniel_B=FCnzli?= Subject: [Caml-list] C interface, threads and ocaml callbacks Date: Wed, 3 Mar 2004 23:51:42 +0100 X-Mailer: Apple Mail (2.612) X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; threads:01 callbacks:01 threads:01 callbacks:01 callback:01 stub:01 -thread:01 stub:01 camlprim:01 callback:01 threading:01 invoke:01 ocaml:01 ocaml:01 caml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 42 Hello, 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 f with the option -thread. 2. In the stub to function f, bracket the call to f with enter/leave_blocking_section(). CAMLprim value f_stub (value v) { /* convert arguments */ enter_blocking_section() res = f(arg) /* In this function threads will try to concurently access ocaml */ leave_blocking_section() /* convert result of f() */ } 3. Around any call from f back into caml, bracket code with leave/enter_blocking_section. leave_blocking_section() /* convert parameters */ res = callback(closure,arg) /* convert result */ enter_blocking_section() 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, Daniel P.S. Is that somewhere documented ? [1] ------------------- 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