Class in thread compiler

Mutex

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

A mutual-exclusion lock that owns a value, made by mutex.

The value is copied into the lock, and with_lock hands the callback a copy and stores the new value it returns. The handle itself can be passed to other threads; every copy refers to the same lock.

Examples#

use thread::{mutex, with_lock, Mutex};
use tests::assert;
let m: Mutex = match mutex(0) {
    Result::Ok(m) => m,
    Result::Err(_) => panic "mutex failed",
};
let _ = with_lock(m, fn (int n) => (n + 5, 0));
let now = match with_lock(m, fn (int n) => (n, n)) {
    Result::Ok(n) => n,
    Result::Err(_) => -1,
};
assert!(now == 5);

See also#

  • thread::mutex
  • thread::with_lock
  • Thread: A handle to a function running on another OS thread, from spawn.
  • Sender: The sending half of a channel made by channel.
  • Receiver: The receiving half of a channel made by channel.
  • RwLock: A readers-writer lock that owns a value, made by rwlock.
↑ ↓ navigate ↵ open