critical sections protecting multiple processes (not threads)

David Carson davidccarson at hotmail.com
Fri Mar 28 11:18:54 EST 2003


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote in message news:<7xel4ujb9s.fsf at ruckus.brouhaha.com>...
> davidccarson at hotmail.com (David Carson) writes:
> > Specifically, I want to test for the existence of a file and open if
> > non-existent in an atomic fashion.  Obviously, if I cannot do this
> > atomically, it is possible for the file to not exist when the test is
> > done but to exist before the creation is done.
> 
> In Un*x, the traditional way is to have a permanent file (call it
> "permfile") and link to it to create the lock file:
> 
>    success = link("permfile", "lockfile");
> 
> If the lockfile already exists, the link attempt will fail.  If the
> lockfile doesn't exist, the link attempt will create it.  This is atomic.

My solution need only be for Unix, so I'm going with this approach. 
Thanks for the tips, Paul and Skip.

David




More information about the Python-list mailing list