Expand description
Rw Cell
rw_cell provides the ability to securely write data from one location of application and read it from another even if Writer and Reader located in different threads without copying/cloning and blocking access to data.
Fun example
fn main() {
let (w0, mut r) = rw_cell::cell(vec!["_"; 1000]);
let w1 = r.get_writer();
let w2 = r.get_writer();
let w3 = r.get_writer();
std::thread::spawn(move || loop {
w0.write(vec!["F"; 1001])
});
std::thread::spawn(move || loop {
w1.write(vec!["u"; 1002])
});
std::thread::spawn(move || loop {
w2.write(vec!["c"; 1003])
});
std::thread::spawn(move || loop {
w3.write(vec!["k"; 1004])
});
let mut count__ = 0;
let mut count_f = 0;
let mut count_u = 0;
let mut count_c = 0;
let mut count_k = 0;
for _ in 0..10000000usize {
match r.read() {
val if val.first() == Some(&"_") => count__ += 1,
val if val.first() == Some(&"F") => count_f += 1,
val if val.first() == Some(&"u") => count_u += 1,
val if val.first() == Some(&"c") => count_c += 1,
val if val.first() == Some(&"k") => count_k += 1,
val => println!("val: {:?}, Not good, but ok", val.first())
}
}
println!("count__: {}", count__);
println!("count_F: {}", count_f);
println!("count_u: {}", count_u);
println!("count_c: {}", count_c);
println!("count_k: {}", count_k);
}Structs
Struct for read data from cell with non-copy and non-lock
Struct for write data in cell with non-copy and non-lock
Functions
Create new cell with
CellWriter and CellReader
Return tuple value and bool value is new or no