Class in thread compiler

RwLock

class RwLock
Import
use thread::{RwLock};
Source: compiler/src/builtin_docs/thread.hy

A readers-writer lock that owns a value, made by rwlock.

Many readers (with_read, try_read) or one writer (with_write, try_write) at a time. Like Mutex, the handle can be passed to other threads.

Examples#

use thread::{rwlock, with_read, with_write, RwLock};
use tests::assert;
let lock: RwLock = match rwlock(1) {
    Result::Ok(l) => l,
    Result::Err(_) => panic "rwlock failed",
};
let _ = with_write(lock, fn (int n) => (n + 1, 0));
let seen = match with_read(lock, fn (int n) => n) {
    Result::Ok(n) => n,
    Result::Err(_) => -1,
};
assert!(seen == 2);

See also#

↑ ↓ navigate ↵ open