1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
extern crate libc;
extern crate winapi;
use Result;
pub use LockGuard;
;
/// 提供进程间的共享内存模块
/// 其中unix使用semget, semctl, semop, 其中用特殊的标识位SEM_UNDO来实现, 防止进程意外退出导致的死锁
/// 其实windows使用CreateMutex, ReleaseMutex, WaitForSingleObject来实现
/// # Examples, Open Double Process for same
///
/// ```no_run
/// 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);
/// }
/// }
/// ```