# threads

> threads, a magmalake tin: 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.

[magmalake](https://magmalake.dev/) [threads](https://magmalake.dev/s/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

mojoshelf:

```
pixi shelf add threads-mojo
```

`pixi shelf` comes with mojoshelf: [install it first](https://mojoshelf.org/getting-started).

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

Source

[GitHub](https://github.com/magmalake/threads.mojo) [README](https://github.com/magmalake/threads.mojo#readme)

## 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

Checked against Contended-count and memory-visibility proofs designed to give a wrong number, not a flake

- [thrift](https://magmalake.dev/s/thrift) compact + binary protocol
- [zstd](https://magmalake.dev/s/zstd) libzstd
- [lz4](https://magmalake.dev/s/lz4) liblz4
- [brotli](https://magmalake.dev/s/brotli) libbrotli
- [snappy](https://magmalake.dev/s/snappy) pure Mojo
- [deflate](https://magmalake.dev/s/deflate) DEFLATE · gzip · pure Mojo
- [hashes](https://magmalake.dev/s/hashes) CRC-32 · murmur3 · XXH64
- [memory-region](https://magmalake.dev/s/memory-region) bytes addressed by offset · shared mappings
- [Every tin](https://magmalake.dev/tins)

[A magmalake project](https://magmalake.dev/)

Apache 2.0 · © 2026 Marius Seritan
