Crates.io | process_lock |
lib.rs | process_lock |
version | 0.1.0 |
source | src |
created_at | 2018-04-24 07:28:40.291196 |
updated_at | 2018-04-24 07:28:40.291196 |
description | This is process lock impl multi process for rust |
homepage | |
repository | https://github.com/tickbh/ProcessLock |
max_upload_size | |
id | 62068 |
size | 15,876 |
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
Licensed under either of
at your option.
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.