API reference
The threads package, from threads 0.6.1, as published on mojoshelf (commit f45e780a8de7), by mojo doc from Mojo 1.2.0.
Source.
Minimal pthreads for Mojo — the threads package of threads.mojo.
Spawn and join OS threads, share state through atomics and a mutex, and fan a
loop out over cores with parallel_for. No dependencies beyond the Mojo
standard library and the pthread symbols every libc already exports.
from threads import parallel_for, num_cpus, AtomicCounter
Start with threads.parallel for the parallel_for contract, threads.pool
for long-lived workers that run until stopped, threads.thread for the thread
and send-contract rules, and threads.atomic for why this tin does not simply
re-export std.atomic.
Modules
-
threads.atomicAtomics that compile on Mojo 1.2.0 and on current nightly. 2 structs · 7 functions -
threads.ffiShared FFI vocabulary: the opaque pointer type everythreadsentry point speaks, and the C NULL convention. 2 functions -
threads.mutexApthread_mutex_t(andpthread_cond_t) you can share between threads. 4 structs -
threads.parallelparallel_for— the reason this tin exists — plus thespawn_n/join_alllayer underneath it. 1 struct · 3 functions -
threads.poolWorkerPool— N long-lived threads that run until you tell them to stop. 2 structs -
threads.threadOS threads:ThreadHandle,num_cpus,current_thread_id, CPU pinning. 1 struct · 4 functions