Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
question of a layman
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Robbert VanRenesse <rvr@c...>
Subject: question of a layman

I have built a complex system in C, and now I'm thinking of options to
re-implement it in CAML.

In short:  we at Cornell University are building a communication system
called Horus.  Horus is a framework that allows the composition of
microprotocols into more complex protocols.  Examples of microprotocols
are sliding window protocols, fragmentation/reassembly protocols, ordering
protocols, and membership protocols.  Each micro-protocol is fairly simple,
and has the *same* top and bottom-level interfaces.  In particular, these
interfaces contain send and deliver.  For example, the sliding window
micro-protocol's send operation adds a sequence number to a message and
invokes the send operation of the micro-protocol below it.

Basically, we can build complex protocols by stacking instances of
micro-protocols on top of each other.  Also, we want to be able to run
multiple stacks at a time (if only to maintain connections to different
peers).  Each instance of a micro-protocol maintains some state.

How would you implement something like this in CAML?  We did an initial
version, which follows the C version and uses mutable records to maintain
the protocol state.  However, even though it works, this does not appear
to me as the most natural way of doing it.

I guess the most natural way of implementing a micro-protocol in CAML is
as a stream to stream function.  A stream is then a stream of send and
deliver (and other) events.  You can then build a stack by composing these

However, two things are still unclear to me:

1) how do you run multiple of these functions at a time in the same
   address space?
2) how do you link it into an existing application written in C.  That is,
   when the C application invokes send(), how do I plug this event into
   the event stream of the function?  And, perhaps the same question, how
   do I make sure that the function maintains its state?

I have a multi-threading system, and I can probably run the CAML interpreter
in thread separate from the application that is written in C, which may be
part of a solution.

I guess the most natural solution would be to run each composition of
stream functions in its own thread, but I don't know how hard this is
to support, or even if this is desirable.  If necessary, I could run
each one in its own address space, but that would be expensive.

I would appreciate any answers/comments.