Directory operations are NOT atomic under NFSv2 and NFSv3
(please refer to the book NFS Illustrated by Brent Callaghan,
ISBN 0-201-32570-5; Brent is a NFS-veteran at Sun).
NFSv2有两个原子操作:
在NFSv3中,创建调用也是原子的。
Knowing this, you can implement spin-locks for files and
directories (in shell, not PHP):
锁定当前目录:
while ! ln -s . lock; do :; done
锁定文件。
while ! ln -s ${f} ${f}.lock; do :; done
解锁(假设,正在运行的进程确实获得了锁)
解锁当前目录:
mv lock deleteme && rm deleteme
un锁定文件。
mv ${f}.lock ${f}.deleteme && rm ${f}.deleteme
Remove is also not atomic, therefore first the rename (which
is atomic) and then the remove.
For the symlink and rename calls, both filenames have to reside on the
same filesystem. My proposal: use only simple filenames and put
file and lock into the same directory.