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 RAA02340; Sat, 12 Oct 2002 17:58:41 +0200 (MET DST) 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 RAA02399 for ; Sat, 12 Oct 2002 17:58:41 +0200 (MET DST) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9CFwdD20881 for ; Sat, 12 Oct 2002 17:58:39 +0200 (MET DST) Received: from ozemail.com.au (syd-ts18-2600-076.tpgi.com.au [203.58.21.76]) (authenticated (0 bits)) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id g9CFwZN22685 for ; Sun, 13 Oct 2002 01:58:36 +1000 Message-ID: <3DA846A8.2030100@ozemail.com.au> Date: Sun, 13 Oct 2002 01:58:32 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Coroutines References: <4.3.2.7.2.20021004000748.030bd2c0@mail.d6.com> <20021006181345.GA23808@strontium.pps.jussieu.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jerome Vouillon wrote: > On Fri, Oct 04, 2002 at 03:25:44AM -0700, Chris Hecker wrote: > >>I'm looking at implementing fibers/coroutines/cooperative-threads >>(described below for reference) in ocaml, and I've run into a small issue, >>a question, and a couple confusions. >> > > I just spent a few hours implementing a small coroutine library. It > is fully written in Ocaml. Below is a quick description. Would it > satisfy your needs ? I can send you a copy, or make it available on the > Web if you like. > > -- Jérôme > > A coroutine returning values of type 'a has type 'a output. > > type 'a output > > You can spawn it. You then get an handle of type 'a input > > type 'a input > val spawn : 'a output -> 'a input > > The caller can get a value from the coroutine. > > val receive : 'a input -> 'a > > A coroutine can return a value of type 'a. > > val send : 'a -> 'a output > These aren't general coroutines, but a subclass I'd call 'filters' corresponding to unix processes with standard input and output. [Felix coroutines are even more restricted .. they can read input, but there is no provision for output.] Despite the apparent lack of generality, a very wide class of coroutines can be implemented by careful choice of the data type 'a, and 'hand written' switches which provide further coroutine emulation within each library coroutine. So I think this library has a good interface, indeed, I'd consider it for the standard distribution. It is simple and lightweight. BTW: I note the interface is 'demand driven' .. you make it work by reading data from the last stage of a filter chain, and control ripples back to the first input stage. Felix, on the other hand, is event driven .. you make it works by sending data to coroutines .. 'Real' coroutines can read and write on multiple channels, exactly like threads with blocking I/O except there is no preemptive switching, obviating the need for thread safe coding. Two well known (and very good) implementations: Windows 3.1 and early Mac OS. Finally .. you might want to consider JoCaml .. it is very beautiful (though the implementation using Posix threads is likely to be slow compared to native exchange of control primitives) -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- 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