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

#55 in Operating systems

Download history 24435/week @ 2025-09-29 22668/week @ 2025-10-06 19557/week @ 2025-10-13 21748/week @ 2025-10-20 19461/week @ 2025-10-27 21241/week @ 2025-11-03 19677/week @ 2025-11-10 28031/week @ 2025-11-17 17746/week @ 2025-11-24 22190/week @ 2025-12-01 21241/week @ 2025-12-08 22503/week @ 2025-12-15 9818/week @ 2025-12-22 8547/week @ 2025-12-29 21221/week @ 2026-01-05 26224/week @ 2026-01-12

67,133 downloads per month
Used in 150 crates (18 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.5–37MB
~482K SLoC