process_lock 0.1.0

This is process lock impl multi process for rust
Documentation
  • Coverage
  • 62.5%
    5 out of 8 items documented0 out of 6 items with examples
  • Size
  • Source code size: 16.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.8 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tickbh/ProcessLock
    2 2 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tickbh

this is process lock impl multi process for rust

Build Status Crates.io

Usage

Add this to your Cargo.toml:

[dependencies]

process_lock = "0.1"

and this to your crate root:

extern crate process_lock;

How to use

extern crate process_lock;
use std::time::{Duration, Instant};
use process_lock::*;
fn main () {
    let mut lock = ProcessLock::new(String::from(".process_lock"), None).unwrap();
    for i in 0..100 {
        let now = Instant::now();
        {
            let _guard = lock.lock().unwrap();
            println!("success get the {} lock lock all use time ===== {}", i, now.elapsed().as_secs());
            let ten_millis = ::std::time::Duration::from_millis(2000);
            ::std::thread::sleep(ten_millis);
        }
        let ten_millis = ::std::time::Duration::from_millis(100);
        ::std::thread::sleep(ten_millis);
    }
}

each process will get the lock in other process release the lock

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.