in reply to File lockingProblem
The algorithm that you describe seems very fragile to me. “It smells really funny. In fact, it smells really bad.” Is there any practical way to redesign this aspect of the system? I would suggest looking around very hard for any other options. flock() is a dependency that is often thought of as being very problematic because of considerable per-filesystem dependencies in its implementation especially when (especially, Unix) networked filesystems are involved. Perhaps this is a situation where you might successfully make the business case that, “we are just down in the wrong rabbit-hole here ...” such that a shift in the architecture of this one key aspect of the system might make a lot of headaches go-away for good, and the time spent dinking around with it until then is simply an ongoing sunk-cost. Maybe what you’ve got right now can’t be made truly reliable and satisfactory. Worth a thought ...