Crates.io | named-lock |
lib.rs | named-lock |
version | 0.4.1 |
source | src |
created_at | 2020-02-07 19:44:52.315127 |
updated_at | 2024-02-28 10:44:31.603758 |
description | Cross-platform implementation of cross-process named locks |
homepage | |
repository | https://github.com/oblique/named-lock |
max_upload_size | |
id | 206065 |
size | 21,630 |
This crate provides a simple and cross-platform implementation of named locks. You can use this to lock sections between processes.
use named_lock::NamedLock;
use named_lock::Result;
fn main() -> Result<()> {
let lock = NamedLock::create("foobar")?;
let _guard = lock.lock()?;
// Do something...
Ok(())
}
On UNIX this is implemented by using files and flock
. The path of the
created lock file will be $TMPDIR/<name>.lock
, or /tmp/<name>.lock
if
TMPDIR
environment variable is not set.
On Windows this is implemented by creating named mutex with CreateMutexW
.