Fixed issue where threaded functions were exiting improperly

This commit is contained in:
= 2022-06-06 19:19:35 -04:00
parent 831abeaccf
commit 89e76ce31d
3 changed files with 21 additions and 15 deletions

View File

@ -1,3 +1,4 @@
print("Dev")
--[[ --[[
MIT License MIT License
@ -1471,6 +1472,7 @@ co_status = {
switch[task](ref,thd) switch[task](ref,thd)
cmds[r1](ref,r2,r3,r4,r5) cmds[r1](ref,r2,r3,r4,r5)
if ret ~= CMD and _ ~= nil then -- The rework makes this necessary if ret ~= CMD and _ ~= nil then -- The rework makes this necessary
print("Hello")
co_status["dead"](thd,ref,task,i,th) co_status["dead"](thd,ref,task,i,th)
end end
r1=nil r2=nil r3=nil r4=nil r5=nil r1=nil r2=nil r3=nil r4=nil r5=nil
@ -1478,6 +1480,7 @@ co_status = {
["normal"] = function(thd,ref) end, ["normal"] = function(thd,ref) end,
["running"] = function(thd,ref) end, ["running"] = function(thd,ref) end,
["dead"] = function(thd,ref,task,i,th) ["dead"] = function(thd,ref,task,i,th)
if ref.__processed then return end
if _ then if _ then
ref.OnDeath:Fire(ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16) ref.OnDeath:Fire(ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16)
else else
@ -1494,6 +1497,7 @@ co_status = {
end end
end end
_=nil r1=nil r2=nil r3=nil r4=nil r5=nil _=nil r1=nil r2=nil r3=nil r4=nil r5=nil
ref.__processed = true
end, end,
} }
handler = coroutine.wrap(function(self) handler = coroutine.wrap(function(self)

View File

@ -139,19 +139,19 @@ function multi.InitSystemThreadErrorHandler()
elseif status == "error" then elseif status == "error" then
livingThreads[temp.Id] = {false, temp.Name} livingThreads[temp.Id] = {false, temp.Name}
temp.alive = false temp.alive = false
temp.OnError:Fire(temp,nil,unpack(temp.returns:receive(0,"returns") or {"Thread Killed!"})) temp.OnError:Fire(temp,unpack(temp.returns:receive(0,"returns") or {"Thread Killed!"}))
GLOBAL["__THREADS__"] = livingThreads GLOBAL["__THREADS__"] = livingThreads
table.remove(threads, i) table.remove(threads, i)
elseif status == "cancelled" then elseif status == "cancelled" then
livingThreads[temp.Id] = {false, temp.Name} livingThreads[temp.Id] = {false, temp.Name}
temp.alive = false temp.alive = false
temp.OnError:Fire(temp,nil,"thread_cancelled") temp.OnError:Fire(temp,"thread_cancelled")
GLOBAL["__THREADS__"] = livingThreads GLOBAL["__THREADS__"] = livingThreads
table.remove(threads, i) table.remove(threads, i)
elseif status == "killed" then elseif status == "killed" then
livingThreads[temp.Id] = {false, temp.Name} livingThreads[temp.Id] = {false, temp.Name}
temp.alive = false temp.alive = false
temp.OnError:Fire(temp,nil,"thread_killed") temp.OnError:Fire(temp,"thread_killed")
GLOBAL["__THREADS__"] = livingThreads GLOBAL["__THREADS__"] = livingThreads
table.remove(threads, i) table.remove(threads, i)
end end

View File

@ -1,18 +1,20 @@
package.path = "./?/init.lua;"..package.path package.path = "./?/init.lua;?.lua;lua5.4/share/lua/?/init.lua;lua5.4/share/lua/?.lua;"..package.path
package.cpath = "lua5.4/lib/lua/?/core.dll;"..package.cpath
multi, thread = require("multi"):init{print=true} multi, thread = require("multi"):init{print=true}
GLOBAL, THREAD = require("multi.integration.threading"):init() GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
test = thread:newFunction(function() test = THREAD:newFunction(function()
PNT()
return 1,2 return 1,2
end,true)
multi:newThread(function()
while true do
print("...")
thread.sleep(1)
end
end) end)
multi:newAlarm(.1):OnRing(function() os.exit() end)
ref = test() print(test())
ref.OnError(function(...) print("Hi!")
print("Got Error",...)
end)
ref.OnReturn(function(...)
print("Got Returns",...)
end)
multi:mainloop() multi:mainloop()