Skip to content

kalix-systems/semalock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

semalock

Crates.io Crates.io Travis

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

Development

You'll need Cargo. More notes to come at a later date.

Releasing

  1. Sanity: cargo clean; cargo test
  2. Upgrade version in Cargo.toml
  3. Commit changes
  4. Create and push a tag: git tag v<version>; git push v<version>
  5. Release on crates.io: cargo publish

Author

Jason Longshore [email protected]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%