2 ms·
His contrived example of "atomically creating a file" is kind of strange. If you would want to see which of several processes wins at creating a file, just use
by cnvogel 17y ago
His contrived example of "atomically creating a file" is kind of strange. If you would want to see which of several processes wins at creating a file, just use
if(-1 != (fd=open("filename",0666,O_CREAT|O_EXCL)){ .. }
which is guaranteed to suceed only for one program.
Or you'd open it without O_EXCL and try locking it. Creating several file and atomically renaming it "over" the old file yields you nothing, because whenver you try to access it afterwards, you have no guarantee that it's not being overwritten just afterwards by another one of the processes.