lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've started to wonder what it would look like to mod the Lua VM to allow multiple threads to run in parallel while referencing the same global Lua state.  I'm imagining an approach that basically just boils down to slipping some mutex locks into the VM to avoid possible memory corruption when two threads try to write to the same table at the same time, which feels like it might be more or less sufficient to allow a preemptive shared-state multithreading mod that would be relatively safe.

More generally, I'm trying to think through what kinds of things might go wrong if one were to just create a collection of coroutines using new_thread(), and then run them in parallel using C multi threading.  Simultaneous table writes, string creation, or garbage collection invocation seem like the most obvious things that could create real trouble, but there's probably some other cases I'm overlooking.

As best as I can tell, there's been one prototype of this kind of Lua mod, Diego Nehab's LuaThread.  I can find the documentation pages on the wayback machine, but, not Diego's source code.

Does anyone have a copy of Diego's LuaThread sources that they could share?

Alternatively, are there any other preemptive, shared state Lua mods out there that people could point me at?

Thanks,

-Sven

http://web.archive.org/web/20070817160033/http://www.cs.princeton.edu:80/~diego/professional/luathread/