System.IO.Lock provides thread-friendly file locks. The locking functions in
System.Posix.IO (actually, it's just
block the entire program, not just the calling thread (even with the
threaded runtime). This module avoids the problem by spawning a new process
for each lock and communicating with it over pipes.
- Only blocks the calling thread
- Works both with and without
- Forks one new process per lock
- Consumes one file descriptor per lock
- Closing the file descriptor doesn't affect the lock (because it's really in
a separate process); you must call
setLock locks the specified region of the file. It blocks the calling thread
until the lock is granted.