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

#60 in Operating systems

Download history 17809/week @ 2024-01-25 15449/week @ 2024-02-01 16173/week @ 2024-02-08 15570/week @ 2024-02-15 15887/week @ 2024-02-22 13223/week @ 2024-02-29 14295/week @ 2024-03-07 15673/week @ 2024-03-14 14371/week @ 2024-03-21 14798/week @ 2024-03-28 12082/week @ 2024-04-04 14088/week @ 2024-04-11 14558/week @ 2024-04-18 13508/week @ 2024-04-25 13237/week @ 2024-05-02 14182/week @ 2024-05-09

58,449 downloads per month
Used in 136 crates (4 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.7–40MB
~593K SLoC