Re: atomically creating a file if it doesn't exist.

From: Don Bennett <dpb_at_pedernales.esd.sgi.com>
Date: Mon, 15 May 95 13:29:39 -0700

> Harvey J. Stein <hjstein_at_MATH.HUJI.AC.IL> wrote:
>
> I'd like to use files for locking (if the lock file exists, the
> resource is locked). This requires the ability to create a file if it
> doesn't exist, and return an error if it does exist (such as with the
> unix system call creat(filename, 666)). Is there a way to do this
> already in STk, or do I need to add creat (or open, for that matter)
> to unix.c? I can't do:
>
> (if (not (file-exists? lockfilename))
> (open-output-file lockfilename
> #f))

My man page for creat(2) says that if the file exists, it does not
return an error, it truncates the file.

I've seen code that does what you want by using
mkdir(2) as the atomic operation to create a lock.

   Don Bennett
   dpb_at_sgi.com
   Silicon Graphics
Received on Mon May 15 1995 - 22:33:10 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST