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 LAA01198; Wed, 16 Jul 2003 11:55:53 +0200 (MET DST) 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 LAA04318 for ; Wed, 16 Jul 2003 11:55:52 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h6G9tif08486; Wed, 16 Jul 2003 11:55:44 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA07647; Wed, 16 Jul 2003 11:55:44 +0200 (MET DST) Date: Wed, 16 Jul 2003 11:55:44 +0200 From: Xavier Leroy To: Likai Liu Cc: caml-list@inria.fr, Likai Liu Subject: Re: [Caml-list] PortAudio on ocaml Message-ID: <20030716115544.A29200@pauillac.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from liulk@bu.edu on Mon, Jul 14, 2003 at 04:55:44PM -0400 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 api:01 callbacks:01 crux:01 callback:01 allocating:01 printf:01 crunch:01 internals:01 runtime:01 model:01 asynchronous:01 invoke:01 ocaml:01 caml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I'm trying to evaluate on porting PortAudio API to O'Caml, which would > enable an entire genre of sound applications being written in this nice > language. What concerns me is that PortAudio uses asynchronous callbacks, > much like signals, to tell the application that some audio sample has > arrived, needs to be played, or both. That's the crux of the problem, indeed. I looked at the PortAudio tutorial and found this little gem: Your callback function is often called by an interrupt, or low level process so you should not do any complex system activities like allocating memory, or reading or writing files, or printf(). Just crunch numbers and generate audio signals. So, calling Caml code from the callback function is definitely out of the question. > [Snipped investigation of internals of OCaml runtime system] > What do the O'Caml developers say about this? That no matter how much you peek under the hood, you cannot meet the requirements of the PortAudio "interrupt handler" model. My advice is that there are essentially only two programming models for C libraries that can reasonably be interfaced with OCaml: - Synchronous calls (block the calling thread till results are available, then return into Caml). - Event loops (register Caml callbacks, then enter a library-provider event handler that will block and invoke the callbacks one at a time, but not from a signal or interrupt context). In both cases, you can make the design thread-compatible by using the Caml runtime system functions enter_blocking_section and leave_blocking_section, see http://caml.inria.fr/archives/200106/msg00199.html - Xavier Leroy ------------------- 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