lock
fn lock(Mutex m) -> Result<unit, ThreadError> Import
Source: use thread::{lock}; compiler/src/builtin_docs/thread.hy Locks m until unlock, waiting while another thread holds it.
This gives no access to the value (use with_lock for that); it only
excludes other lock / with_lock callers. A thread can hold one mutex
through lock at a time: a second lock before unlock is
Err(ThreadError::Other).
Parameters#
| Name | Type |
|---|---|
m | Mutex |
Returns#
Result<unit, ThreadError>
Examples#
use thread::{mutex, lock, unlock};
use tests::assert;
let m = match mutex(0) {
Result::Ok(m) => m,
Result::Err(_) => panic "mutex failed",
};
assert!(match lock(m) { Result::Ok(_) => true, Result::Err(_) => false });
assert!(match unlock(m) { Result::Ok(_) => true, Result::Err(_) => false });
See also#
thread::unlockthread::with_lockspawn: Runsf(arg)on another OS thread and returns a handle to it.join: Waits for the thread to finish and returns the value its function returned.detach: Lets the thread run to completion without being joined.channel: Creates an unbounded channel and returns its(Sender, Receiver)ends.send: Sends a copy ofvalueon the channel.recv: Takes the next value from the channel, waiting until one arrives.