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 MAA02910; Fri, 13 Dec 2002 12:27:48 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA02905 for caml-list@pauillac.inria.fr; Fri, 13 Dec 2002 12:27:47 +0100 (MET) 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 XAA21152 for ; Thu, 12 Dec 2002 23:15:56 +0100 (MET) Received: from star2.baremetal.com (star2.baremetal.com [216.86.113.248]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gBCMFs113453 for ; Thu, 12 Dec 2002 23:15:55 +0100 (MET) Received: from blackfen.com (h139-142-123-131.gtcust.grouptelecom.net [139.142.123.131]) by star2.baremetal.com (8.12.4/8.12.4) with ESMTP id gBCMKew5032587 for ; Thu, 12 Dec 2002 14:20:40 -0800 Date: Thu, 12 Dec 2002 14:17:42 -0800 Subject: Re: [Caml-list] Resource acquisition is initialization Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v548) From: Quetzalcoatl Bradley To: Caml Users Mailing List Content-Transfer-Encoding: 7bit In-Reply-To: <20021212141506.A24877@pauillac.inria.fr> Message-Id: <88762044-0E1F-11D7-BC2C-003065AB3928@blackfen.com> X-Mailer: Apple Mail (2.548) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday, December 12, 2002, at 05:15 AM, Xavier Leroy wrote: > For a mutex: > > let synchronize mut action = > try > Mutex.lock mut; > let res = action () in > Mutex.unlock mut; > res > with x -> > Mutex.unlock mut; > raise x > > You get the idea. For fun I try to use campl4 to add synchronize directive. usage: synchronize "expression that evaluates to Mutex.t" in "expression" The value is result of "expression". Example: let lock = Mutex.create ();; let counter = ref 0;; let next_sym prefix = synchronize lock in let current = !counter in counter := current + 1; prefix ^ (string_of_int current) ;; synchronize.ml file: open Pcaml;; EXTEND expr: LEVEL "expr1" [[ "synchronize"; e1 = expr; "in"; e2 = expr -> <:expr< let __synchronize_lock = $e1$ in do { Mutex.lock __synchronize_lock; try let __synchronize_result = $e2$ in do { Mutex.unlock __synchronize_lock; __synchronize_result } with z -> do { Mutex.unlock __synchronize_lock; raise z } } >> ]]; END;; ------------------- 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