in reply to flock -- and indefinite wait

I would recommend reading through Dominus's excellent presentation, File Locking Tricks and Traps. In particular, Slide 8 talks about different methods of handling waiting for a lock if it cannot be obtained immediately.