unlock
fn unlock(Mutex m) -> Result<unit, ThreadError> Import
Source: use thread::{unlock}; compiler/src/builtin_docs/thread.hy Releases a mutex this thread locked with lock or try_lock.
Returns Err(ThreadError::Other) if this thread does not hold m.
Parameters#
| Name | Type |
|---|---|
m | Mutex |
Returns#
Result<unit, ThreadError>
Examples#
use thread::{mutex, lock, unlock, ThreadError};
use tests::assert;
let m = match mutex(0) {
Result::Ok(m) => m,
Result::Err(_) => panic "mutex failed",
};
let _ = lock(m);
assert!(match unlock(m) { Result::Ok(_) => true, Result::Err(_) => false });
let not_held = match unlock(m) {
Result::Err(ThreadError::Other) => true,
default => false,
};
assert!(not_held);
See also#
thread::lockthread::try_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.