Yes, and while that handles the common (mistaken) case of
- open for append
- flock 2
- append
- unflock
- close
that does nothing for
- open for read/write
- flock 2
- read/write
- unflock
- repeat back to step 2 as needed
Because there's nothing in that sequence that refreshes the buffer between flock 2 and read, and yet someone else could have messed with the file to get your buffer and the file out of sync. So still, unflock is almost always a danger sign,
even with the workaround.
In summary: unflock (flock 8) is not needed when you're about to close, and
has to be handled very carefully if you're leaving the file open. Don't use unflock until you know why I say don't use unflock. {grin}
-- Randal L. Schwartz, Perl hacker