Was file locking ever meant to work?
summary
Compares BSD flock, POSIX fcntl locks and the Linux-only open file description locks, showing concrete failures: BSD can be silently no-op or translate to POSIX on NFS, fcntl releases locks on the first close so threads can accidentally drop locks, and mandatory locks are broken and unsupported. Builds a working libvirt solution using POSIX locks but isolates locking into a short-lived forked helper so locks behave as if single threaded; shows SQLite’s messy pthread+fcntl workaround and explains why PID files safely use BSD locks.
AI-written summary · about
chapters (9)
- 0:00File locking challenges
- 1:33Scenarios requiring file locks
- 3:41Types of file locks
- 6:12BSD locks inconsistencies
- 7:16POSIX locks pitfalls
- 10:55Lockf and open file locks
- 12:23Mandatory locks risks
- 13:06Libvirt's file locking
- 15:48Q&A on POSIX locks
related talks
13mLockify: Understanding Linux Distributed Lock Management Overheads in Shared Storage
01h 04mBetter mutual exclusion on the filesystem using Boost.AFIO
40mKernel Locking Engineering
59mThe Wild West of post-POSIX IO Interfaces
25mAdaptive futexes: spin if the owner is still running on another CPU
21mState of futex2
45mContainer Kernel Development
42mUnix For Rubyists
