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

#35 in Operating systems

Download history 17702/week @ 2024-11-30 16655/week @ 2024-12-07 14295/week @ 2024-12-14 4206/week @ 2024-12-21 4620/week @ 2024-12-28 14448/week @ 2025-01-04 19742/week @ 2025-01-11 15640/week @ 2025-01-18 16139/week @ 2025-01-25 17826/week @ 2025-02-01 19874/week @ 2025-02-08 17343/week @ 2025-02-15 18364/week @ 2025-02-22 16777/week @ 2025-03-01 16814/week @ 2025-03-08 14424/week @ 2025-03-15

69,898 downloads per month
Used in 139 crates (7 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–34MB
~486K SLoC