in reply to Disappearing File

I don't think this has anything to do with locking.

In this case, without proper locking, the worst thing can happen is that you don't get the correct increment, but there is no chance that your counter will be decreased.

For example, your currect counter = 100, both process A and B try to increase the counter by 1. Somehow your locking failed, both A and B read 100, and then write 101 back. Your counter still increases, although it only increased by 1, instead of the right increment 2.

The fact your counter is going down, must be caused by some other defect(s).

Replies are listed 'Best First'.
Re: Re: Disappearing File
by Gorby (Monk) on Jan 13, 2004 at 07:17 UTC
    What you have said is true. There really should be no case where the counter will decrease, even if the lock fails. My question is, what's causing the file to be deleted? The code I provided is the only code that edits the "counter" file. Gorby
      Just a thought, but in all the times I've written flocking apps, I've always used append mode instead of create mode. Perhaps I do this because somewhere I've got bitten by create mode removing the file to create it empty, and that of course would have another locker still holding the old (unlinked) file locked, even though I can now lock the new one.

      Try changing your lockfile open to an append, and rerun your tests. I apologize if that doesn't fix it, but it is suspicious.

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