critical sections protecting multiple processes (not threads)

Paul Rubin http
Wed Mar 26 18:19:43 CET 2003


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.




More information about the Python-list mailing list