Reproduction is simple. Not sure if this is feature or bug
local tab = {}
tab.num = 1
task.spawn(function()
local num = tab.num + 1
tab.num = num
print(tab.num, "a")
end)
local num = tab.num + 1
tab.num = num
print(tab.num, "b")
If you place a breakpoint on every line and step through everything with the debugger, the output is:
2 b
3 a
If you remove all breakpoints and execute the output is:
2 a
3 b
This is a pretty minor inconsistency, but I’d like to know why it happens. I ran into this when I was doing some testing of code that runs into race conditions, but I can’t solve race conditions if I can’t trust that the debugger output will match real output.
The bit of code above shows that when not debugging, any spawned thread (through task.spawn) will execute immediately, before the chunk below runs. The debugged output shows that task.spawn defers its thread? Which shouldn’t occur, since if you wanted to defer a thread, you’d use task.defer