![]() |
|
Your skill will accomplish what the force of many cannot |
|
PerlMonks |
RE: RE: RE: RE: Flock Subroutineby turnstep (Parson) |
on Aug 08, 2000 at 04:35 UTC ( #26707=note: print w/replies, xml ) | Need Help?? |
Well, using anything incorrectly can lead to problems, but I still think a simple flock is best - just be careful about it. > Here you should be able to see the race. Another process
I don't agree with this. First, if another process cannot get an exclusive lock while *any* other lock is on it. So if process A locks a file for reading (shared lock) and then process B tries to get an exclusive lock, process B cannot get the lock until *all* the locks are gone - shared and exclusive. In the second case, yes it's a problem, but that's a bad coding problem, not a problem with flock. The right way to do it of course is to open the file for read/write, get an exclusive lock, read in the file, rewind (usually), write to the file, and close it, releasing the exclusive lock.
No need for a semaphore, just change the above a bit:
And yes, I need to update my tutorial. :)
In Section
Meditations
|
|