cvs commit: src/usr.bin/lockf lockf.c
Christian S.J. Peron
csjp at FreeBSD.org
Wed Oct 5 10:39:16 PDT 2005
csjp 2005-10-05 17:39:15 UTC
FreeBSD src repository
Modified files:
usr.bin/lockf lockf.c
Log:
Fix long standing race condition associated with how lockf uses open(2)
for mutual exclusion:
A brief description of the problem:
1) Proc A picks up non-blocking lock on file X
2) Proc B attempts to pickup lock, fails then waits
3) Proc C attempts to pickup lock, fails then waits
4) Proc A releases lock
5) Proc B acquires lock, release it to pickup a non-blocking version
6) Proc C acquires lock, release it to pickup a non-blocking version
7) Both process B and C race each other to pickup lock again
This occurs mainly because the processes do not keep the lock after they have
been waiting on it. They drop it, attempt to re-acquire it. (They use the wait
to notify when the lock has become available then race to pick it up). This
results in additional CPU utilization during the race, and can also result
in processes picking locks up out of order.
This change attempts to correct this problem by eliminating the test/acquire
race and having the operating system handle it.
Reported by: kris
Tested by: kris
MFC after: 1 week
Revision Changes Path
1.12 +8 -30 src/usr.bin/lockf/lockf.c
More information about the cvs-src
mailing list