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-27 (14:31)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [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?

I believe the solution you outline in your message is correct:

> 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.

Agreed.  Moreover, you should make sure that window_proc is always
called from a thread that was created by Caml, and not some other
thread created by the system.  (I don't believe Windows message
handling creates such extra threads, though.)

- Xavier Leroy
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