5 releases (3 breaking)

0.4.1 Feb 28, 2024
0.4.0 Feb 28, 2024
0.3.0 Sep 17, 2022
0.2.0 Apr 21, 2022
0.1.1 Feb 8, 2020

#72 in Operating systems

Download history 16424/week @ 2024-08-15 16077/week @ 2024-08-22 14173/week @ 2024-08-29 18280/week @ 2024-09-05 18084/week @ 2024-09-12 17649/week @ 2024-09-19 19774/week @ 2024-09-26 19831/week @ 2024-10-03 19356/week @ 2024-10-10 22868/week @ 2024-10-17 21164/week @ 2024-10-24 17801/week @ 2024-10-31 14697/week @ 2024-11-07 18330/week @ 2024-11-14 17777/week @ 2024-11-21 10970/week @ 2024-11-28

64,742 downloads per month
Used in 138 crates (6 directly)

MIT license

18KB
328 lines

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.

Dependencies

~0.6–36MB
~553K SLoC