caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Coroutines
Date: Sun, 13 Oct 2002 01:58:32 +1000	[thread overview]
Message-ID: <3DA846A8.2030100@ozemail.com.au> (raw)
In-Reply-To: <20021006181345.GA23808@strontium.pps.jussieu.fr>

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


  parent reply	other threads:[~2002-10-12 15:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-04 10:25 [Caml-list] gc question: thread stacks, fibers, etc Chris Hecker
2002-10-06 18:13 ` [Caml-list] Coroutines Jerome Vouillon
2002-10-06 19:46   ` Chris Hecker
2002-10-12 15:58   ` John Max Skaller [this message]
2002-10-12 16:33 ` [Caml-list] gc question: thread stacks, fibers, etc John Max Skaller
2002-10-12 18:54   ` Chris Hecker
2002-10-13  8:32 ` Xavier Leroy
2002-10-14  7:18   ` Chris Hecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3DA846A8.2030100@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).