9fans archive / 1998 / 02 / 19 /    prev next

From: G. David Butler gdb@dbS...
Subject: [9fans] create(2)/open(2) race for file creation
Date: Sat, 7 Feb 1998 23:09:45 -0600

>From: "Rob Pike" <rob@pla...>
>Am I missing something?   If everyone does create(file, OWRITE, 000)
>only one process can succeed.   Perm==0 means no one can read or
>write the file; if you want one writer, many readers, 004 will do.

If I want to create the file, write data and close so that it can
be read/written again then I can't leave it 000 or 400, I must
leave it 600.  So, if many processes are doing:

if stat() fails {
	create()
	write()
	chmod()
	close()
}

Then it is possible for two or more processes to fail the stat
but one to create, write, chmod and close before the other others
do create.  It is a race that can't be avoided, that I can see.

>In other words, it's a create/open race, so don't run that race.

I would like to avoid it.  Your point is valid if the file is
created once and never written to again.  That is a big restriction.