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 BAA02641; Wed, 10 Mar 2004 01:23:36 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA02788 for ; Wed, 10 Mar 2004 01:23:35 +0100 (MET) Received: from mail4.bluewin.ch (mail4.bluewin.ch [195.186.4.74]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i2A0NYHd003353 for ; Wed, 10 Mar 2004 01:23:34 +0100 Received: from [10.0.1.2] (62.203.46.90) by mail4.bluewin.ch (Bluewin AG 7.0.024) id 4048E4A200085F20; Wed, 10 Mar 2004 00:23:34 +0000 In-Reply-To: <200403050213.i252DtGV029925@mailserver2.hushmail.com> References: <200403050213.i252DtGV029925@mailserver2.hushmail.com> Mime-Version: 1.0 (Apple Message framework v612) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Message-Id: <4A6D8484-7229-11D8-8391-000393DBC266@epfl.ch> Content-Transfer-Encoding: quoted-printable Cc: caml-list@inria.fr From: =?ISO-8859-1?Q?Daniel_B=FCnzli?= Subject: Re: [Caml-list] C interface, threads and ocaml callbacks Date: Wed, 10 Mar 2004 01:24:27 +0100 To: annan@hushmail.com X-Mailer: Apple Mail (2.612) X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 threads:01 callbacks:01 -threads:01 threads:01 -threads:01 -thread:01 runtime:01 serialize:01 callbacks:01 threading:01 internals:01 ocaml's:01 threading:01 waits:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 100 Le 5 mars 04, =E0 03:13, annan@hushmail.com a =E9crit : > If I understand what you are trying to do, most likely you can't do > it. If you build ocaml code with -threads, you like with the thread- > aware basic library. Once you do this, you can't use threads you=20 > created > in the C execution context, as there is information required by Ocaml > when executing library functions that gets created when *IT* uses=20 > threads, > that isn't there when C creates threads. > > So if you create all of your threads in Ocaml, then you can use=20 > -threads, > but if C creates threads, those threads cannot execute OCaml code. My understanding of the -thread flag --- drawn from message [1] --- is=20= that when you compile with it, then you just get this master lock on=20 the runtime that you can release/get by using=20 enter/leave_blocking_section functions. Though the initial purpose of=20 the latter functions was --- it seems --- to give the opportunity to=20 ocaml signal handlers to execute during long running C code that=20 doesn't interact with ocaml, it seems that you can also use this=20 mechanism to serialize concurrent callbacks from C into ocaml (by=20 wrapping the callbacks around leave/enter_blocking_section to=20 get/release the master lock). > You can have C threads execute inside Ocaml, if you don't use the=20 > OCaml > threading library. This seems match what is described in that message [2], though --- due=20= to my lack of knowledge about the internals of ocaml's threading=20 libraries --- I don't really understand the reason. > So if you can get away with just one OCaml thread, > but need multiple C threads, then gatekeep the entry of C threads = into > the OCaml code (ie have the OCaml code go through a C function that=20 > pthread_cond_waits A lock/unlock on a mutex around the callbacks from C into caml should=20 be sufficent, hence the use of -thread and=20 enter/leave_blocking_section. Unfortunately I hadn't any time these days to experiment the approach I=20= described in my previous message. Thanks for you answer. Daniel [1] [2] ------------------- 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