Expand description
Exclusive lock files whose body names the holder.
The session journal lock and the keeper locks write the holder’s identity
into the locked file, so a process that is refused can say who has it. On
Unix the lock is an advisory flock, which never blocks a read. Windows
byte-range locks are mandatory: fs4 (like File::try_lock) locks the whole
file from offset 0, so the refused process could not read the body and
every refusal lost its holder (“held by another process”). There the lock
covers one byte far past any body instead. That byte lies inside the
whole-file range, so it still excludes, and is excluded by, a binary that
locks the whole file.
A lock is released by dropping its ExclusiveLock, which unlocks
explicitly before the file closes. Closing alone is not enough: a flock
belongs to the open file description, and a child forked by any thread of
this process holds a copy of every descriptor until it execs (O_CLOEXEC
applies only at exec). Until then the lock would outlive its owner, and an
immediate re-lock be refused in the name of this very process. Windows
releases a closed handle’s locks only “depending on available system
resources”, so there an explicit unlock is what makes the release prompt.
Structs§
- Exclusive
Lock - An exclusive lock on a file, released when dropped.
Functions§
- try_
lock - Take the exclusive lock on
filewithout waiting:Ok(None)if another handle holds it.