named-lock

Crates.ionamed-lock
lib.rsnamed-lock
version0.4.1
sourcesrc
created_at2020-02-07 19:44:52.315127
updated_at2024-02-28 10:44:31.603758
descriptionCross-platform implementation of cross-process named locks
homepage
repositoryhttps://github.com/oblique/named-lock
max_upload_size
id206065
size21,630
Yiannis Marangos (oblique)

documentation

README

named-lock

license crates.io docs

This crate provides a simple and cross-platform implementation of named locks. You can use this to lock sections between processes.

Example

use named_lock::NamedLock;
use named_lock::Result;

fn main() -> Result<()> {
    let lock = NamedLock::create("foobar")?;
    let _guard = lock.lock()?;

    // Do something...

    Ok(())
}

Implementation

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.

Commit count: 24

cargo fmt