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
Callbacks from C to OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-07-11 (07:54)
From: ygrek <ygrekheretix@g...>
Subject: Re: [Caml-list] Callbacks from C to OCaml
On Fri, 10 Jul 2009 12:16:17 +0100
"David Allsopp" <> wrote:

> Now, at any time, the SCM may invoke the ServiceCtrlHandler function
> registered with it. This also needs to callback to an OCaml function to work
> out what to do (the closure was registered in the initial call).
> What happens at this point with regard to OCaml's global lock and being in
> the correct threading context? I must confess that I don't fully understand
> how the callback works at all in the single-threaded context - presumably
> when SCM calls the function, it simply executes code in its own thread
> context (so it can presumably introduce a form of multi-threading to a
> program which isn't expecting it?).

Yes, SCM creates new thread for the callback.
And this thread is not registered with OCaml runtime, and so
you can't do any allocation on it. I used windows services in the same setup and  
just set a boolean flag when SCM signalled service to stop, while periodically checking
this flag in ocaml thread..

See also

Hope it helps.