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 JAA18588; Wed, 19 May 2004 09:32:50 +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 JAA18591 for ; Wed, 19 May 2004 09:32:49 +0200 (MET DST) From: thornber@redhat.com Received: from mx1.redhat.com (mx1.redhat.com [66.187.233.31]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4J7WlEV027743 for ; Wed, 19 May 2004 09:32:48 +0200 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i4J7WlGG015373; Wed, 19 May 2004 03:32:47 -0400 Received: from pobox.surrey.redhat.com (pobox.surrey.redhat.com [172.16.10.17]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i4J7Wk019983; Wed, 19 May 2004 03:32:46 -0400 Received: from localhost (vpn50-22.rdu.redhat.com [172.16.50.22]) by pobox.surrey.redhat.com (8.12.8/8.12.8) with ESMTP id i4J7Wjtl031625; Wed, 19 May 2004 08:32:46 +0100 Received: from localhost ([127.0.0.1] helo=nimzo) by localhost with smtp (Exim 4.21) id 1BQLZc-00089o-BJ; Wed, 19 May 2004 08:33:08 +0100 Received: by nimzo (sSMTP sendmail emulation); Wed, 19 May 2004 08:33:08 +0100 Date: Wed, 19 May 2004 08:33:08 +0100 To: SWAMPY Cc: caml-list Subject: Re: [Caml-list] Functional critical section Message-ID: <20040519073308.GA29514@nimzo> References: <1084869517.19838.409.camel@pelican.wigram> <20040518090635.GA6918@bourg.inria.fr> <1084875941.19838.446.camel@pelican.wigram> <20040518121147.GA20094@redhat.com> <1084910535.30471.49.camel@ice.gerd-stolpmann.de> <006801c43d14$61edef40$10015c0a@word> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <006801c43d14$61edef40$10015c0a@word> User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 40AB0D9F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 0400,:01 wrote:03 let:04 let:04 raise:05 redhat:05 equivalent:05 functional:06 arg:06 arg:06 mutex:06 mutex:06 fun:08 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, May 18, 2004 at 04:10:44PM -0400, SWAMPY wrote: > Then, I could do something like: > > critical (threadsafeFunction arg1 arg2 arg3) > > and have this do the equivalent of > > Mutex.lock someMutex; let tmp = threadsafeFunction arg1 > arg2 arg3; Mutex.unlock someMutex; tmp;; I use a 'with_resource' function: | let try_finally fn fin = | try | let result = fn () in | fin (); | result; | with x -> fin (); raise x | | let with_resource resource fn post = | try_finally (fun () -> fn resource) (fun () -> post resource) Which could be used to make a 'with_file' or 'with_mutex' fn: | let with_file file fn = | with_resource (open_in file) fn close_in | | let with_mutex fn = | with_resource (Mutex.lock someMutex) fn Mutex.unlock - Joe ------------------- 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