Browse thread
[Caml-list] enter_blocking_section / leave_blocking_section question
- Harry Chomsky
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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(...)
{
enter_blocking_section();
SendMessage(...);
leave_blocking_section();
}
LRESULT window_proc(...)
{
leave_blocking_section();
callback(...); // call OCaml window proc
enter_blocking_section();
}
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