Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Best way to synchronize OS processes?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-12 (12:53)
From: Gerd Stolpmann <info@g...>
Subject: Re: [Caml-list] Best way to synchronize OS processes?
Am Mit, 2004-05-12 um 13.27 schrieb Alex Baretta:
> Shawn Wagner wrote:
> > 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?
> > 
> > 
> > File locking with Unix.lockf?
> I disagree. I faced the same problem and found that it cannot be easily 
> solved with lockf. Unix.lockf locks specific regions in a file, whereas 
> Ranjan seems to need the equivalent of a mutex, which should be 
> implemented as a lock over the entire file. This is done by the flock 
> primitive in Posix systems. Unluckily, flock has not been included in 
> the Unix module.

And this is good. flock is not as portable as lockf. flock usually does
not work over NFS, whereas lockf works. Normally, you need flock only to
synchronize with third-party BSD programs such as sendmail.

lockf does not lock regions of a file. It just locks abstract
byteranges, whether you interpret them as file regions is up to you.
That means, you can lock byteranges that do not exist in the file. If
you like, you can view an empty lockf-locked file as 2^32 potential
mutexes (or whatever the maximum file size is).

Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: