1 个不稳定版本
使用旧的 Rust 2015
0.1.2 | 2017年2月17日 |
---|---|
0.1.1 |
|
0.1.0 |
|
15 在 #reads 中排名 #15
每月下载量 41 次
4KB
54 行
一个允许无限数量的并发读取的锁,这些读取永远不会被阻塞。同一时间只能有一个写者访问资源。
示例
use rculock::{RcuLock, RcuGuard};
// Create a new RcuLock protecting a piece of data, in this case a number (u32).
let data: RcuLock<u32> = RcuLock::new(5);
assert_eq!(5, *data.read());
{
// The data is cloned and handed to the writer
let mut guard: RcuGuard<u32> = data.write();
// RcuGuard implements `Deref` and `DerefMut` for easy access to the data.
*guard = 4;
// The writer has changed its copy of the data, but the changes
// have not yet made it back to the master `RcuLock`.
assert_eq!(5, *data.read());
}
// After the write guard is dropped, the state of the resource
// as the writer sees it is atomically stored back into the master RcuLock.
assert_eq!(4, *data.read());
依赖项
~1MB
~18K SLoC