How does Defold handle multithreading?

If you write a native extension to do something you can have threads to do work. If you do need to do things which would block normal gameplay you should try to do it in NE threads, on some platforms like HTML5 this won’t help though because everything is forced single thread due to security requirements.

Otherwise Lua coroutines are not threads, there is nothing special done with that as far as I know. Would be cool if it was possible! Like ways to write async Lua containers that are run on their own actual threads so as to not block the main thread and can pass data as needed.

Some parts may be threaded but currently others like built in audio are not. You should generally assume things done in Lua are not threaded.

I think http.request() calls are threaded. Some resource loaded may be threaded but even with async set it can still lag your game, even audio will pause/glitch in some cases since it’s not threaded yet.

Of course the source is available now so you can read it yourself to see how it actually all works.

Something like the “simplified overview” to compliment Defold application lifecycle manual would be cool to see.

4 Likes