Version française
Home     About     Download     Resources     Contact us    
Browse thread
C-threads & callbacks
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: C-threads & callbacks
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