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 http://caml.inria.fr/mantis/view.php?id=4702 Hope it helps. -- ygrek