good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^2: File Locking plus delete Lockfile questionby rovf (Priest) |
on Feb 12, 2009 at 12:15 UTC ( [id://743284]=note: print w/replies, xml ) | Need Help?? |
While I question the sanity of wanting to delete the lockfile (you do realize that other processes may already have opened the file and are all waiting to grab the lock?)Indeed, this could be a problem which I didn't see before. The problem is that I really would like to go away the lockfile. The reason is that in my application, we have not just one lock file of this type, but we create maybe a hundred or so per day, each guarding its own "checkin/checkout" system. At one point in time, this system will cease to exist, but because of the distributed nature of the application, no single instance has the knowledge whether or not a single "checkin/checkout" system is still alive or not. We only know that *if* the number of customers is still greater than 0, it is alive. Otherwise, it may be dead. Initially, there is no lockfile at all (that's why I also pass the CREATE flag to sysopen. If the customer count drops back to zero one time, and I find a safe way to delete the lockfile, there is no harm done. If a new customer arrives later (i.e. it turns out that the system is not dead yet), the lockfile is simply recreated. If I don't delete the lockfile, I would either need an external instance which manages whether a specific checkin/checkout system is alive or dead (and erase the lockfiles of the dead ones), or I would end up with a large number of unused lockfiles. Thinking about your argument, I fear that the only safe way would be to do some kind of centralization. Probably I will end up having a single lockfile common to all "checkin/checkout" systems on each host and handle the customer count separately. Thank you for pointing out the flaw in my algorithm.
-- Ronald Fischer <ynnor@mm.st>
In Section
Seekers of Perl Wisdom
|
|