Expand description
Cross-process named locks.
ipc-lock provides mutual exclusion that works across both threads and
processes on the same machine.
§How it works
Two locking layers work together:
-
OS-level — keeps different processes out.
- Unix:
flock(2)viastd::fs::File::lockon a file under$TMPDIR. - Windows: a
Global\named kernel mutex viaCreateMutexW. If the previous owner terminates without releasing the mutex, the next waiter acquires it successfully butLockGuard::is_abandonedreturnstrue.
- Unix:
-
Thread-level — keeps different threads in the same process from entering concurrently, because
flockandCreateMutexWare process-granular primitives that allow re-entry from the same process without blocking. Implemented with aMutex<bool>gate and aCondvar.
§Example
use ipc_lock::{Lock, Result};
fn main() -> Result<()> {
let lock = Lock::new("my-app")?;
let _guard = lock.lock()?; // blocks until available
// critical section …
Ok(()) // _guard dropped → lock released
}Lock is cheap to clone — all clones share the same underlying state.
let lock = Lock::new("shared")?;
let other = lock.clone(); // cheap Arc cloneStructs§
- Lock
- A cross-process named lock.
- Lock
Guard - RAII guard returned by
Lock::lockandLock::try_lock.
Enums§
Type Aliases§
- Result
- Specialized
Resultfor this crate.