-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Godot threads from Lua #9
Comments
The problem with multithreading and Lua is that the VMs, at least standard PUC-Rio Lua and LuaJIT, are not thread-safe. We could create new states for each thread in the C land before calling to Lua, which doesn't seem that bad, but then how would data sharing work? Maybe making the script instance not be a table and use only Godot data like Dictionaries? What about globals variables? Should we patch That's why I think Lua PluginScript should probably just not deal with this, it's no easy task and there are already options out there for multithreading, although they will probably not work directly with Godot's |
Good to know. I figured out a solution by communicating with a gdscript object, but I just wanted to make sure that's the "intended" way to do things in this case. So thanks for the explanation! |
I don't know if "intended" is the best word for this, but yeah. |
Spawning new Lua states is likely the best approach for multithreading in the language. LuaJIT exploits single threaded nature of Lua extensively when dealing with the global table (or references in general). |
I agree, we cannot multithread safely in LuaJIT without spawning new Lua states. Godot's Array and Dictinaries are thread-safe if you don't change their container size, so they could be shared between threads, even across Lua states, as they're still just pointers (like Do you have any thoughts on how thread support could be implemented? |
@Calandiel most of the reasoning is already in this thread, but I think the problem is mostly about how to interface this threading stuff with the Godot side of things. |
Is there a proper way to use one of Godot's native threads from a Lua script? I've tried simply doing something like:
But this just causes the game to crash with no error reported.
I know one of the stated non-goals is "Support multithreading on the Lua side" but I'm not sure if that's what you meant or if you simply meant native Lua multithreading.
The text was updated successfully, but these errors were encountered: