ls-flock provides process-shared advisory file locks over POSIX lockf.
POSIX record locks never conflict within the owning process, so calls using
the same pathname namestring are additionally serialized by a process-wide
mutex. Threads of one image using the same pathname namestring serialize, and
separate processes exclude each other through the operating-system lock.
(ls-flock:with-file-lock (#P"/var/lib/app/store.lock")
(rewrite-the-store))
(ls-flock:call-with-file-lock #P"/var/lib/app/store.lock"
(lambda () (rewrite-the-store)))Scoped locks wait for other holders. The lock file is created with mode
0600 (override with :mode) and intentionally left behind on release so
later holders can reuse it. Acquisition failures signal FILE-LOCK-ERROR;
conditions from the body propagate unchanged and still release the lock.
(let ((lease (ls-flock:lease-acquire #P"/var/lib/app/session.lock")))
(unwind-protect
(serve-the-session)
(ls-flock:lease-release lease)))A lease is an exclusive claim acquired without waiting, held until it is
released or its owner exits.
When this process already holds a live lease on the pathname, or another
process owns the lock, acquisition signals FILE-LOCK-BUSY, a subtype of
FILE-LOCK-ERROR. LEASE-RELEASE is idempotent, LEASE-HELD-P reports
liveness, and a crashed owner’s leftover lock file is reusable immediately
because the operating system drops the lock with the process.
A fork child inherits the parent’s tables but none of its POSIX locks;
call RESET-AFTER-FORK in the child before using ls-flock there.
(asdf:test-system :ls-flock)The suite includes a cross-process probe that spawns a second Lisp to prove operating-system-level exclusion, not only thread-level exclusion.
./script/bootstrap
./script/check
./script/check --fix./script/check runs the tests, then checks the source with
cheque as cheque.sexp
configures it. --fix skips the tests and repairs what cheque can repair.
cheque and its tools are development dependencies: checks/qlfile lists them,
and the check installs them on first use into ~/.cache/cheque/tools/.
Part of the Lambda Symbolics library shelf.