RwLock
class RwLock Import
Source: use thread::{RwLock}; compiler/src/builtin_docs/thread.hy A readers-writer lock that owns a value, made by rwlock.
Many readers (with_read, try_read) or one writer (with_write,
try_write) at a time. Like Mutex, the handle can be passed to other
threads.
Examples#
use thread::{rwlock, with_read, with_write, RwLock};
use tests::assert;
let lock: RwLock = match rwlock(1) {
Result::Ok(l) => l,
Result::Err(_) => panic "rwlock failed",
};
let _ = with_write(lock, fn (int n) => (n + 1, 0));
let seen = match with_read(lock, fn (int n) => n) {
Result::Ok(n) => n,
Result::Err(_) => -1,
};
assert!(seen == 2);
See also#
thread::rwlockthread::with_readthread::try_readthread::with_writethread::try_writethread::MutexThread: A handle to a function running on another OS thread, fromspawn.Sender: The sending half of a channel made bychannel.