1# named-lock
2
3[![license][license badge]][license]
4[![crates.io][crate badge]][crate]
5[![docs][docs badge]][docs]
6
7This crate provides a simple and cross-platform implementation of named locks.
8You can use this to lock sections between processes.
9
10## Example
11
12```rust
13use named_lock::NamedLock;
14use named_lock::Result;
15
16fn main() -> Result<()> {
17    let lock = NamedLock::create("foobar")?;
18    let _guard = lock.lock()?;
19
20    // Do something...
21
22    Ok(())
23}
24```
25
26## Implementation
27
28On UNIX this is implemented by using files and [`flock`]. The path of the
29created lock file will be `$TMPDIR/<name>.lock`, or `/tmp/<name>.lock` if
30`TMPDIR` environment variable is not set.
31
32On Windows this is implemented by creating named mutex with [`CreateMutexW`].
33
34
35[license]: LICENSE
36[license badge]: https://img.shields.io/github/license/oblique/named-lock
37[crate]: https://crates.io/crates/named-lock
38[crate badge]: https://img.shields.io/crates/v/named-lock
39[docs]: https://docs.rs/named-lock
40[docs badge]: https://docs.rs/named-lock/badge.svg
41
42[`flock`]: https://linux.die.net/man/2/flock
43[`CreateMutexW`]: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createmutexw
44