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 UAA17048; Tue, 11 May 2004 20:10:47 +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 UAA18152 for ; Tue, 11 May 2004 20:10:46 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4BIAjEV007324 for ; Tue, 11 May 2004 20:10:45 +0200 Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 1BNbiG-0003Ts-00 for ; Tue, 11 May 2004 19:10:44 +0100 Date: Tue, 11 May 2004 19:10:44 +0100 Cc: caml-list@inria.fr Subject: Re: [Caml-list] Best way to synchronize OS processes? Message-ID: <20040511181044.GA13360@redhat.com> References: <40A115E3.1060400@frotz.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <40A115E3.1060400@frotz.com> User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at nez-perce with ID 40A11725.001 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 serialize:01 lockf:01 val:01 lockf:01 lseek:01 footprints:01 giants:99 ltd:98 0700,:01 command:98 int:01 synchronize:01 unix:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, May 11, 2004 at 11:05:23AM -0700, Ranjan Bagchi wrote: > Hi -- > > I'm writing some code which will end up executing concurrently on > several OS processes. I'd like to serialize access to some specific OS > resources (for instance, writing to a single file). The Unix module > doesn't appear to offer anything like a critical section or an OS > mutex. Is there a preferred way to do this? What about Unix.lockf? Rich. val lockf : file_descr -> lock_command -> int -> unit (** [lockf fd cmd size] puts a lock on a region of the file opened as [fd]. The region starts at the current read/write position for [fd] (as set by {!Unix.lseek}), and extends [size] bytes forward if [size] is positive, [size] bytes backwards if [size] is negative, or to the end of the file if [size] is zero. A write lock (set with [F_LOCK] or [F_TLOCK]) prevents any other process from acquiring a read or write lock on the region. A read lock (set with [F_RLOCK] or [F_TRLOCK]) prevents any other process from acquiring a write lock on the region, but lets other processes acquire read locks on it. *) -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment If I have not seen as far as others, it is because I have been standing in the footprints of giants. -- from Usenet ------------------- 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