in reply to Re: Re: Order of flock and open
in thread Order of flock and open

I think what you want is what I wrote in "Exclusively updating a file that continues to be repeatedly read". Yours looks a bit fishy, like there are still places where two people can have locks on what should be the only copy. And then there's the problem of a dead process after renaming the input file but not yet renaming the output file. Now you have a missing file!

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Re: Re: Order of flock and open
by bluto (Curate) on Apr 30, 2003 at 21:54 UTC
    I agree that it is fishy and I would never use it in practice (the reason for the lack of real code and the disclaimer in the last line of the post) since over the years I've learned that once you start messing around with operation ordering too much, and start requiring non-blocking locks, chances are good the locking strategy is incorrect.

    That said, I'm not entirely convinced that it can't be fixed, perhaps by using only a single rename, only that it isn't worth it. Your solution is more elegant in any case.

    bluto