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

#65 in Operating systems

Download history 6687/week @ 2023-12-23 9534/week @ 2023-12-30 14773/week @ 2024-01-06 16218/week @ 2024-01-13 17561/week @ 2024-01-20 17074/week @ 2024-01-27 15870/week @ 2024-02-03 16684/week @ 2024-02-10 15208/week @ 2024-02-17 14619/week @ 2024-02-24 13260/week @ 2024-03-02 15304/week @ 2024-03-09 15355/week @ 2024-03-16 15600/week @ 2024-03-23 12907/week @ 2024-03-30 9807/week @ 2024-04-06

56,148 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–41MB
~592K SLoC