From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id FAA25031; Thu, 23 May 2002 05:32:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA25165 for ; Thu, 23 May 2002 05:32:31 +0200 (MET DST) Received: from mail.speakeasy.net (mail12.speakeasy.net [216.254.0.212]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g4N3WWT02931 for ; Thu, 23 May 2002 05:32:32 +0200 (MET DST) Received: (qmail 22442 invoked from network); 23 May 2002 03:32:27 -0000 Received: from unknown (HELO harry) ([64.81.246.34]) (envelope-sender ) by mail12.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 23 May 2002 03:32:27 -0000 Message-ID: <00e401c2020a$78463230$0200a8c0@harry> From: "Harry Chomsky" To: "Caml-list" Subject: [Caml-list] enter_blocking_section / leave_blocking_section question Date: Wed, 22 May 2002 20:32:30 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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