rwlock
fn rwlock<T>(T initial) -> Result<RwLock, ThreadError> Import
Source: use thread::{rwlock}; compiler/src/builtin_docs/thread.hy Creates a readers-writer lock holding a copy of initial.
The value must be sendable (see spawn), or the result is
Err(ThreadError::NotSendable).
Parameters#
| Name | Type |
|---|---|
initial | T |
Returns#
Result<RwLock, ThreadError>
Examples#
use thread::{rwlock, with_read};
use tests::assert;
let lock = match rwlock("config") {
Result::Ok(l) => l,
Result::Err(_) => panic "rwlock failed",
};
let n = match with_read(lock, fn (string s) => s.len()) {
Result::Ok(n) => n,
Result::Err(_) => 0,
};
assert!(n == 6);
See also#
thread::spawnjoin: 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.try_send: Sendsvaluewithout waiting.try_recv: Takes the next value if there is one, without waiting.