Is it (theoretically) possible to modify LuaJIT to support shared-memory multithreading?

  • From: Paul Baker <paulbaker8@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 15 Sep 2016 02:16:24 +1200

AFAIK, Lua states in LuaJIT can only be accessed by a single thread at
a time. If multiple threads in an application need to run Lua code, it
is necessary to create one Lua state per thread.

Would it be (theoretically) possible to modify LuaJIT so that multiple
threads could share a Lua state and run the same Lua code in parallel?
If so, what precautions would the Lua code have to take (e.g.
presumably it would have to use locks when accessing tables shared
between threads)?

Or is the design of the JIT (or another part of LuaJIT, e.g. the
garbage collector) fundamentally single-threaded?

Other related posts: