TIL: Multithreading in Lua
Concurrency in Lua
Today I was solving day 5, part 2 of Advent of Code 2023:
which I hoped to optimize using concurrency (as it involves millions of computations).
As I’m doing these puzzles in Lua this year, I first looked at Lua coroutines, but these alone are not enough to achieve true concurrency in the sense of multithreading (using a single CPU) or parallelism (using multiple CPUs).
Luv
There is, however, a project luv
that offers bindings of libuv (a multi-platform support library for asynchronous I/O, primarily developed for Node.js) for LuaJIT:
It comes with extensive documentation and a folder of examples: