4 ms·
Unsure what "massive concurrency means". As far as I'm aware zig offers no special primitives for threading (other than tools in a standard library to start/sto
by laserbeam 4y ago
Unsure what "massive concurrency means". As far as I'm aware zig offers no special primitives for threading (other than tools in a standard library to start/stop threads and such). Async/await/suspend/resume are features used for concurrency (yielding on a single thread).
You then use those primitives to implement parallelism however you want. Just like you'd do in C. Or, ykno, someone makes a library that does green threads the way you want using those primitives.
- carlmr 4y agoSo Go has a two things that enable massive concurrency. 1. Coroutines have dynamic stacks, meaning that you can start a lot of threads without exhausting your memory: https://medium.com/a-journey-with-go/go-how-does-the-goroutine-stack-size-evolve-447fc02085e5 https://medium.com/a-journey-with-go/go-how-does-the-gorouti... 2. Go has a lightweight threading model that doesn't map one thread to one OS/kernel level thread. Enabling you to have thousands of threads operating at once. limited by GOMAXPROCS. I was just wondering because the article mentioned Zig having a lot of the benefits of Rust and Go, and this is one thing where Rust doesn't shine, so I was wondering if they had an answer for this.
- fbouvier 4y agoAs said by @laserbeam there is no implementation of concurrency built-in Zig language, just primitives. There is one event loop in the stdlib, but it has some limitations and there is some discussion to change it or remove it https://github.com/ziglang/zig/issues/8224 https://github.com/ziglang/zig/issues/8224 Some Zig libraries implementing an event loop: - libxev by Mitchell Hashimoto https://github.com/mitchellh/libxev https://github.com/mitchellh/libxev - one from the Tigerbeetle DB https://github.com/tigerbeetledb/tigerbeetle/tree/main/src/io https://github.com/tigerbeetledb/tigerbeetle/tree/main/src/i... They both use kernel concurrency features (io_uring/epool on Linux, kqueue on MacOS). They are quite low level and do not implement a lightweight threading model comparable to Go concurrency.
- kristoff_it 4y agoGo style concurrency can be also implemented in Zig, with the caveat that since Zig doesn't have a runtime / gc, you can't expect full 1:1 mapping with what Go provides. IMO the key point of Go's concurrency are channels, and those have already been implemented in Zig, with comparable semantics (eg blocking when the channel is full). Here is how I use a channel (defined a few lines above) to implement the main loop of an interactive program I wrote: https://github.com/kristoff-it/bork/blob/master/src/main.zig#L160-L267 https://github.com/kristoff-it/bork/blob/master/src/main.zig...