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
[Caml-list] enter_blocking_section / leave_blocking_section question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-05-23 (03:32)
From: Harry Chomsky <harry@c...>
Subject: [Caml-list] enter_blocking_section / leave_blocking_section question
I'm starting to use threads with my OCaml-Win32 library, and I'd like to
annotate it with appropriate calls to enter_blocking_section and
leave_blocking_section.  Clearly, if I make a call to a Win32 API function
that may take some time, I'll surround the call with enter_blocking_section
/ leave_blocking_section.  But what if that function may make a callback to
my own code, which may in turn pass control back to OCaml?

For instance, my OCaml code calls send_message, implemented as C code that
calls the Win32 SendMessage function.  If I'm sending a message to a system
window, SendMessage just returns.  But if I'm sending a message to an
OCaml-owned window, my C window procedure will be called, and that in turn
will call an OCaml window procedure.

I'm inclined to do something like this:

CAMLprim value send_message(...)

LRESULT window_proc(...)
    callback(...); // call OCaml window proc

Obviously I'll need to guarantee that whenever window_proc is called, it
happens during a blocking section.  Is it safe then for window_proc to
temporarily "suspend" the blocking section?  The enter_ and leave_ calls
will always occur in the proper alternation, but the stack will be in a
different state when leave_ is called than when enter_ was called.  I just
want to make sure that this still constitutes safe and proper use of the
blocking system.

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners