To this end, I propose a threading API. To spawn a new thread, you might do this:
Code: Select all
local mydata
-- .....
minetest.thread("path/to/file.lua", mydata, local function(result)
-- process result in callback here
end);
Code: Select all
local mydata = thread.get_data() -- Unsure about this - any better ideas would be great!
local result = {}
-- do stuff here
return result
- The main server thread cannot access any data inside the newly thread
- Likewise, the new thread cannot access anything in the main thread
- The minetest API is unavailable in the new thread (except for thread.get_data() or however the new thread gets the data passed to it
- Data is copied when being transferred from one thread to another (zero-copy would be nice, but I recognise that would probably be very difficult to implement)
Thoughts?