caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus.mottl@gmail.com>
To: Vincenzo Ciancia <vincenzo_mlRE.MOVE@yahoo.it>,
	SooHyoung Oh <shoh@compiler.kaist.ac.kr>,
	Alex Baretta <alex@barettadeit.com>,
	Olivier Andrieu <oandrieu@nerim.net>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: C-threads & callbacks
Date: Mon, 24 Jan 2005 15:00:35 -0500	[thread overview]
Message-ID: <20050124200035.GA12714@quant3.janestcapital.quant> (raw)
In-Reply-To: <20050121.011925.78707709.oandrieu@nerim.net> <41F0A45A.2080806@barettadeit.com> <41F057D2.4020407@compiler.kaist.ac.kr> <200501211042.31749.vincenzo_mlRE.MOVE@yahoo.it>

Hi,

thanks for all the replies.  I have just implemented a solution, which
seems to be very satisfactory for our purposes.

On Fri, 21 Jan 2005, SooHyoung Oh wrote:
> I'v resolved the same problem using TCP/IP communication between Ocaml
> thread and C thread.

This would unfortunately have been way too much overhead.

On Fri, 21 Jan 2005, Alex Baretta wrote:
> What exactly are you doing, Markus? I'm interested because we, too, here 
> at DE&IT, use Ocaml for realtime applications.

We are logging financial realtime data (trades) with enormously high
data volume (tens of thousands of ticks/trades per second at peak times).

On Fri, 21 Jan 2005, Olivier Andrieu wrote:
> What about using a pipe ? the C callback stuffs its data in the pipe
> (perhaps converted to marshalled caml values) and on the other end,
> the caml callback is waiting with a blocking read.

This would still require marshalling overhead.

My solution now looks as follows:

I prespawn an OCaml-thread, which immediately goes into C-land.
There it waits on a condition variable (within a blocking section to
let other OCaml-threads run) until some C-thread makes data available
and notifies it.  Then the OCaml-thread converts the available data to
OCaml-values and performs the callback.  In the meanwhile the C-thread
blocks on a condition variable until the result is available.  Once the
OCaml-thread returns, it notifies the C-thread and waits for more data
again.  The C-thread continues as desired (terminates or does something
else, etc.).

The only overhead is context switching, everything else is negligible.

It would still be nice if there were an easy way to let C-threads safely
migrate to OCaml-land without all this thread-coordination...

Regards,
Markus

-- 
Markus Mottl    markus.mottl@gmail.com    http://www.ocaml.info


  parent reply	other threads:[~2005-01-24 20:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-20 18:23 Markus Mottl
2005-01-20 18:58 ` [Caml-list] " Daniel Bünzli
2005-01-20 19:23   ` Markus Mottl
2005-01-20 19:37 ` Alex Baretta
2005-01-20 20:19   ` Markus Mottl
2005-01-21  1:16 ` SooHyoung Oh
2005-01-21  6:42   ` Alex Baretta
     [not found]     ` <200501211042.31749.vincenzo_mlRE.MOVE@yahoo.it>
2005-01-24 20:00       ` Markus Mottl [this message]
2005-01-30 10:19 ` Xavier Leroy

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=20050124200035.GA12714@quant3.janestcapital.quant \
    --to=markus.mottl@gmail.com \
    --cc=alex@barettadeit.com \
    --cc=caml-list@inria.fr \
    --cc=oandrieu@nerim.net \
    --cc=shoh@compiler.kaist.ac.kr \
    --cc=vincenzo_mlRE.MOVE@yahoo.it \
    /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).