8 个版本 (4 个破坏性更新)
0.4.3 | 2019年11月14日 |
---|---|
0.4.2 |
|
0.4.1 | 2019年10月28日 |
0.4.0 | 2019年5月14日 |
0.0.0 | 2018年6月19日 |
#73 在 #mutable
每月51次下载
用于 breezy-timer
17KB
278 行
类型级别的安全可变全局访问,支持递归不可变锁定。
use global::Global;
// The global value.
static VALUE: Global<i32> = Global::new();
// Spawn 100 threads and join them all.
let mut threads = Vec::new();
for _ in 0..100 {
threads.push(std::thread::spawn(|| {
*VALUE.lock_mut().unwrap() += 1;
}));
}
for thread in threads {
thread.join().unwrap();
}
// This value is guaranteed to be 100.
assert_eq!(*VALUE.lock().unwrap(), 100);
依赖
~0.6–11MB
~108K SLoC