Available

amalgame-threading

Mutex, Channel, Thread.Spawn — wraps pthread.

amc package add threading GitHub ↗ ← Back to the ecosystem

Overview

Cross-OS concurrency primitives: threads, mutexes, bounded FIFO channels. Wraps pthread on Linux/macOS and Win32 Threads on Windows. GC-safe registration for Boehm GC. The layer that makes Mosaic's worker pool possible.

Features

  • Thread.Spawn(fn) / Join() / Sleep(ms)
  • Mutex.New(), Lock(), Unlock()
  • Bounded FIFO Channel<T>.New(capacity)
  • Internal condition variables for Channel
  • GC-safe registration under pthread/Win32

Example

Minimal usage example — copy-paste runnable after install.

amc package add threading

let ch = Channel<int>.New(16)
Thread.Spawn(fn() {
    for i in 0..10 { ch.Send(i) }
    ch.Close()
})
while let v = ch.Recv() {
    Console.WriteLine(v)
}

At a glance

Related packages