English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

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: 2005-01-20 (19:23)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] C-threads & callbacks
Daniel Bünzli schrieb am Donnerstag, den 20. Jänner 2005:
> I don't understand what you are refering to. I don't think there's a 
> problem as long as you take care to acquire ocaml's global lock to 
> exectue the callbacks.
> #include <caml/signals.h>
> ...
> caml_leave_blocking_section();
> callback(*caml_named_value("myfun"), Val_unit);
> caml_enter_blocking_section();
> ...
> This ensures that callbacks into caml are properly serialized.

This only works if the callback is performed by a thread that was
spawned by OCaml (i.e. OCaml -> C -> OCaml).  In this case the runtime
knows what the "current thread" is.  But if a C-thread executes
"caml_leave_blocking_section" (C -> OCaml), it can segfault there,
because there may be no "current thread".  And if there is, it is not
the C-thread but another currently executing OCaml-thread, which will
mess things up later.

That's why there should be some way to register a C-thread with the
OCaml-runtime.  Currently this does not seem to be possible without
hacking the OCaml-implementation.


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