Function in thread compiler

rwlock

fn rwlock<T>(T initial) -> Result<RwLock, ThreadError>
Import
use thread::{rwlock};
Source: 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#

NameType
initialT

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::spawn
  • 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 of value on the channel.
  • recv: Takes the next value from the channel, waiting until one arrives.
  • try_send: Sends value without waiting.
  • try_recv: Takes the next value if there is one, without waiting.
↑ ↓ navigate ↵ open