Is HDB locking safe?
Leslie Mikesell
les at chinet.chi.il.us
Sat Aug 18 10:24:09 AEST 1990
In article <YZ85N+6 at xds13.ferranti.com> peter at ficc.ferranti.com (Peter da Silva) writes:
>> (a) A "sleep(1);" is not enough to avoid a race on a very busy system.
>No sleep is ever enough. The system could simply be busier than you ever
>imagined. You don't solve a race problem by narrowing the window: try
>checking the return value of the "unlink": that's the point of failure.
No, there is no problem if the unlink fails since the creation of a new
lock file is done in such a way that only one process will succeed. The
problem occurs when a process tests one lockfile and decides that no
current process owns it, but the unlink() instead removes a file that was
just created by another program going through a similar procedure. The
sleep after the unlink() is intended to give any other processes that
have read the contents of the old lockfile time to complete their unlink()
call before a valid file is created.
Les Mikesell
les at chinet.chi.il.us
More information about the Comp.unix.wizards
mailing list