in reply to race condition? - flock and $SIG{ALRM}

To your first question, "Yes but don't worry about that race condition."

If you get the lock and then die, has harm been done? Of far greater concern is that Perl's signal handler is not very reliable. If it matters to you then you really do not want to use it.

Secondly JanneVee is absolutely right that this is the kind of problem that transactions are meant for. If you can just shove the problem to a database that has them. If you cannot then make sure you work in units where you aquire the lock, do the work, and then commit it.

Rules on transactional stuff that will save a lot of grief for you: Until the moment you commit, do not touch any original data. If committing takes time the first step is to back up the original data, move in changed data then delete backup. Under no circumstances at any point assume you will be successful. Finally look around and you will find a number of useful snippets for locking. For instance Simple Locking or you can find more from Super Search.

  • Comment on RE (tilly) 1: race condition? - flock and $SIG{ALRM}