Problem with multithreading

local function heavyTask(...)
   -- Some heavy task, calculations, creating parts, etc
end	

local taskCoro = coroutine.create(heavyTask)
local success, result = coroutine.resume(taskCoro, ...)

print("free")

So ideally the game should run smooth while stuff is being done on the coroutine (another CPU core), but it doesn’t. It freezes the game (fps 0) and "free" feels printed after it. If I put wait()s in heavyTask then it works as expected but slow.

Coroutines are not run on different CPU cores. Only one coroutine can run at a time. You’ll need to use parallel lua if you want multithreading. However it’s still in beta.

2 Likes