The Perl 5.x documentation states that its implementation of flock(..) will use one of the following native calls, starting at 1 and working toward 3 if unavailable:
- flock(2)
- fcntl(2)
- lockf(3)
That's fine. However, you may have noticed their disclaimer that flock(2) should not be used over a NFS. The doc suggests using a -Ud_flock flag to force Perl to use flock(2). The man page of flock(2) (on Redhat) states a similar disclaimer about NFS issues.
My question is, why!?!? I can't seem to find an in-depth article or explanation of WHY flock(2) is unsafe over a NFS.
I've written several test scripts in C and Perl, on both Redhat (where flock(2) is being used) and on Solaris (where fcntl(2) is being used). I ran strace/truss to ensure that Perl was indeed using flock(2) and fcntl(2) respectively. I could not replicate any issues where a lock was not being honored! What gives??