Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Anastasia Gornostaeva <ermine@ermine.pp.ru>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] unix.select + camlp4
Date: Tue, 03 Jul 2007 02:44:50 +1000	[thread overview]
Message-ID: <1183394690.11863.22.camel@rosella.wigram> (raw)
In-Reply-To: <20070702153934.GA1911@ermine.home>

On Mon, 2007-07-02 at 19:39 +0400, Anastasia Gornostaeva wrote:
> On Mon, Jul 02, 2007 at 12:10:34PM +1000, skaller wrote:
> > On Mon, 2007-07-02 at 01:01 +0400, Anastasia Gornostaeva wrote:
> > > On Sun, Jul 01, 2007 at 09:37:46PM +0100, Jon Harrop wrote:
> > 
> > > I dont understand: Try:
> > > 1) It receives "1-2+3*" and parses it. 
> > > 2) Later it receives "4" and continues parsing.
> > > 
> > > I want to get non-blocking parser. How to implement?
> > 
> > Put the parser in a thread, select in another thread.
> > Use Stream.from f for the parser. Write f to get characters
> > using the Event module, send the characters from the other thread
> > after select makes a channel active.
> 
> It looks awful if you want to run houndreds streams/connections.
> It is easier to run a connection with a parser in separate thread.
> So, camlp4 cannot be nonblocking parser.. bad.

This problem is not restricted to parsers .. it's a general
problem with Ocaml and also C, C++, and most other languages.

My language Felix solves this problem for procedures with
user space threading .. but it doesn't work with functions.
[And the builtin GLR parser is purely functional:]

Other languages like Scheme and I think Haskell and MLton
have more general solutions because they're not restricted
to the archaic concept of a linear stack.

You can certainly write code using continuation passing style
to work around this deficiency in most languages, but you
can't work around someone else's code that doesn't use this
style.

The general model of using 'threads' is the only solution,
however OS threads are too general and too slow for large
numbers, and they're needlessly asynchronous when all you
often want is control inversion (though in your case,
you're using 'select' so you do want asynchronicity).

JoCaml is worth looking at for another approach.. but the
bottom line is if you're using the usual parser products
around, the only way to control invert the 'get_token'
callback is by using a pair of threads implementing
a client/server model, and allowing the OS to control
invert the threads by stack swapping.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


      reply	other threads:[~2007-07-02 16:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-01 20:30 Anastasia Gornostaeva
2007-07-01 20:37 ` [Caml-list] " Jon Harrop
2007-07-01 21:01   ` Anastasia Gornostaeva
2007-07-02  2:10     ` skaller
2007-07-02 10:06       ` Phd position at LACL, University of Paris 12 Frédéric Gava
2007-07-02 15:39       ` [Caml-list] unix.select + camlp4 Anastasia Gornostaeva
2007-07-02 16:44         ` skaller [this message]

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=1183394690.11863.22.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=ermine@ermine.pp.ru \
    /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