It's not threading per-se. It's collaborative multithreading.4aiman wrote:Merged both.
Thanks for help, guys!
PS: I believe the only thing that needs to be in a separate thread is logging. (Don't confuse logging with debug info and writing to StdErr output.)
Very often when I think smth is slow, simple deletion of any output to the terminal make things usable.
I don't say we don't need threading, but single core PCs won't benefit from it much.
What this means is that a routine suspends execution ("yields") to the caller routine.
What the patch does is incrementally generate the formspec at each game step. This means the server does not get frozen in the for loop, yielding at every line of the map.
When this happens, the server regains control, and allows other mods (and the game itself) to do their stuff. Then, at the next game step, it resumes the "threads" to generate another map line, and so on until it is complete and the map is shown to the player. It's not perfect, but at least leaves some time for other tasks.
EDIT: This also means no real threads are created. For more info, see this: http://www.lua.org/manual/5.1/manual.html#2.11