Tins · Primitives
threads
Minimal OS threads for Mojo: spawn and join pthreads, share state through atomics and a mutex, and fan a loop out over cores with parallel_for. A stopgap, distilled from flare, until the language ships its own.
Install
plain pixi:
pixi init app -c https://conda.modular.com/max -c conda-forge && cd app
sed -i.bak 's/^\[workspace\]/[workspace]\npreview = ["pixi-build"]/' pixi.toml
pixi add "mojo-compiler==1.2.0"
# Without mojoshelf: the tin as a git dependency at its published commit.
# Transitive dependencies may be wrong: pixi takes the tin's own git deps as
# pinned in its pixi.toml, which may not match what other tins pin, and then
# fails with "duplicate records". mojoshelf picks revisions that agree.
pixi add threads-mojo --git https://github.com/magmalake/threads.mojo --rev f45e780a8de77278c140cee36904e46e93e0ca1c No mojoshelf needed. If pixi reports duplicate records, the mojoshelf tab picks revisions that agree.
Version
0.6.1 on mojoshelf
What it does
Works today
- parallel_for over cores — Mojo currently ships no other way to use a second one
- Atomics that bridge the stable/nightly std.atomic split
- Mutex, spawn, join and thread pinning
- Typed parallel_for and TypedPool: shared state held alive by origin, the void* erasure inside the library
Correctness
Checked against Contended-count and memory-visibility proofs designed to give a wrong number, not a flake