Mutex
class Mutex Import
Source: use thread::{Mutex}; compiler/src/builtin_docs/thread.hy A mutual-exclusion lock that owns a value, made by mutex.
The value is copied into the lock, and with_lock hands the callback a
copy and stores the new value it returns. The handle itself can be passed
to other threads; every copy refers to the same lock.
Examples#
use thread::{mutex, with_lock, Mutex};
use tests::assert;
let m: Mutex = match mutex(0) {
Result::Ok(m) => m,
Result::Err(_) => panic "mutex failed",
};
let _ = with_lock(m, fn (int n) => (n + 5, 0));
let now = match with_lock(m, fn (int n) => (n, n)) {
Result::Ok(n) => n,
Result::Err(_) => -1,
};
assert!(now == 5);
See also#
thread::mutexthread::with_lockThread: A handle to a function running on another OS thread, fromspawn.Sender: The sending half of a channel made bychannel.Receiver: The receiving half of a channel made bychannel.RwLock: A readers-writer lock that owns a value, made byrwlock.