Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@maxtal.com.au>
Cc: caml-list@inria.fr
Subject: Control inversion
Date: Thu, 06 Apr 2000 02:02:32 +1000	[thread overview]
Message-ID: <38EB6398.72F562F4@maxtal.com.au> (raw)
In-Reply-To: <Pine.BSF.4.21.0004040837190.4012-100000@shell5.ba.best.com>

Given a 'functional/procedural' program which does blocking read
operations,
usually modelled by threading constructions, can we transform this
program into one which operates entirely synchronously using
callbacks from a message dispatcher (where the messages are the
same data that the blocking read would have fetched?

I call this process 'control inversion', because it turns master into
slave, and vice versa: the read 'subroutine' called by the master
algorithm, is turned inside out so that the code is executed
by returning control, and then continuing via a callback (making
the code a slave of the dispatcher).

The requirements for control inversion are to save the state of the
environment and point of control, and to restore the state, modified
by the presence of the 'read' message, at the next point of control.
With 'heavyweight' threads, function programs using the machine stack
are control inverted by operating system level stack/register saving.

With (ultra) lightweight threads, we cannot use the machine stack,
except temporarily, so we must maintain a 'stack' manually,
which is difficult to implement .. by hand. But it should not be so hard
to add 'control inversion' to a bytecode machine.
This has been done for Python (by Chritian Tismer, called Stackless
Python).
But it should also be possible for generated code.

I have a clue that for Haskell, the notion of 'arrows' was invented
to replace monads (these arrows correspond to arrows of categories)
for just this purpose (the application here was thousands of
concurrent interactive web sessions, where existing technology
requires 'recording' the state between interactions in an extremely
clubsy ad hoc (usually perlish) way. My application is different,
but the requirements seem the same.

I'm currently using ocaml to implement a simplistic language
which provides 'automatic' control inversion (allowing programmers
to write threaded programs instead of event driven ones).
Unfortunately, the technique is to generate C++ code.

I'd be very interested to hear more from those that know more about
the inner workings of ocaml, whether there is a possible 'native'
solution to this problem. I imagine this would require language
constructions to specify threads (rather than just a library
function call/calls).

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net



  reply	other threads:[~2000-04-06 13:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-17 19:30 to have labels or not Jan Brosius
2000-03-19  4:39 ` Brian Rogoff
2000-03-22  2:30   ` Markus Mottl
2000-03-23  0:57     ` Max Skaller
2000-03-23  3:46       ` Markus Mottl
2000-03-23 23:22         ` Max Skaller
2000-03-28  1:07         ` Julian Assange
2000-03-24  2:41       ` Jacques Garrigue
2000-03-25  3:12         ` Markus Mottl
2000-03-25  3:57         ` John Max Skaller
2000-03-29 20:32           ` Brian Rogoff
2000-03-30  9:56             ` John Max Skaller
2000-04-04  6:53             ` Jacques Garrigue
2000-04-04 13:04               ` John Max Skaller
2000-04-04 16:39               ` Brian Rogoff
2000-04-05 16:02                 ` John Max Skaller [this message]
2000-04-06 13:43                 ` Pierre Weis
2000-04-06 16:33                   ` Andrew Conway
2000-03-28  1:04     ` labels, Hash.create Julian Assange

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=38EB6398.72F562F4@maxtal.com.au \
    --to=skaller@maxtal.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