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

#81 in Operating systems

Download history 22593/week @ 2024-10-21 20227/week @ 2024-10-28 15323/week @ 2024-11-04 16357/week @ 2024-11-11 19798/week @ 2024-11-18 13449/week @ 2024-11-25 18080/week @ 2024-12-02 16433/week @ 2024-12-09 13834/week @ 2024-12-16 3961/week @ 2024-12-23 5265/week @ 2024-12-30 14756/week @ 2025-01-06 19488/week @ 2025-01-13 15797/week @ 2025-01-20 16166/week @ 2025-01-27 17370/week @ 2025-02-03

69,276 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–35MB
~497K SLoC