5 unstable releases
Uses old Rust 2015
0.3.1 | Feb 26, 2020 |
---|---|
0.3.0 | Sep 14, 2019 |
0.2.0 | May 15, 2018 |
0.1.1 | May 12, 2018 |
0.1.0 | May 12, 2018 |
#931 in Concurrency
41 downloads per month
14KB
220 lines
semalock
semalock is a Rust library for controlling concurrent access to files on POSIX operating systems in an efficient manner.
It uses a combination of POSIX named semaphores and exclusive file locks to safely and efficiently acquire exclusive access to a file. This has been observed to be particularly efficient on Linux, with under 5% of CPU time spent on lock overhead with 8192 processes.
Usage
The following shows usage of semalock. This program opens /some/file
and appends some text to it. Try it with GNU parallel to measure performance amongst multiple competing processes.
// Acquire and open a file and semaphore
let mut lock = Semalock::new(Path::new("/some/file"));
// Do some stuff to the file
lock.with(|lock| {
lock.file
.seek(SeekFrom::End())
.and_then(|_| lock.file.write(b"hello world\n"))
});
Supported Operating Systems
The following operating systems have been tested:
- GNU/Linux 4.16
The following operating systems have not been tested but should work:
- FreeBSD
- GNU/Linux 2.6+
- macOS 10.4+
- NetBSD
- OpenBSD
Supported operating systems must support provide the following:
- flock
- sem_get_value
- sem_open
- sem_post
- sem_timedwait
- sem_unlink
The following will not work:
- Windows NT
Release Notes
0.3.1 - 2020-02-25
- Fix a compilation error on x86
0.3.0 - 2019-09-13
Semalock::with
now takes anFnOnce
instead of anFn
.- Various project hygiene changes
0.2.0 - 2018-05-14
- Initial release.
Developer Notes
To run the tests, execute the following:
cargo test
To release the create, perform the following:
- Edit
Cargo.toml
, bumping the version as appropriate. - Edit
README.md
, adding an entry to the Release Notes. - Commit these changes and push them to
master
. - Create and push a tag that starts with "v" -- e.g. "v0.4.0"
Author
Jason Longshore hello@jasonlongshore.com
Dependencies
~1.6–10MB
~113K SLoC