Added test cases for threading, fixed issues. Todo test love2d

This commit is contained in:
2023-04-25 00:13:47 -04:00
parent d2cfdfa8e8
commit 61b5ea9d14
7 changed files with 149 additions and 42 deletions
+7 -2
View File
@@ -114,7 +114,6 @@ function multi:newSystemThreadedJobQueue(n)
link = c.OnJobCompleted(function(jid,...)
if id==jid then
rets = {...}
link:Destroy()
end
end)
return thread.hold(function()
@@ -278,7 +277,13 @@ function multi:newSystemThreadedConnection(name)
self.links = {}
self.proxy_conn = multi:newConnection()
local mt = getmetatable(self.proxy_conn)
setmetatable(self, {__index = self.proxy_conn, __call = function(t,func) self.proxy_conn(func) end, __add = mt.__add})
local tempMT = {}
for i,v in pairs(mt) do
tempMT[i] = v
end
tempMT.__index = self.proxy_conn
tempMT.__call = function(t,func) self.proxy_conn(func) end
setmetatable(self, tempMT)
if self.CID == THREAD.getID() then return self end
thread:newThread("STC_CONN_MAN"..name,function()
local item
+12 -9
View File
@@ -95,10 +95,11 @@ function multi:newSystemThread(name, func, ...)
globals = globe,
priority = c.priority
},function(...)
require("multi"):init(multi_settings)
multi, thread = require("multi"):init(multi_settings)
require("multi.integration.lanesManager.extensions")
local has_error = true
return_linda:set("returns",{func(...)})
returns = {pcall(func, ...)}
return_linda:set("returns", returns)
has_error = false
end)(...)
count = count + 1
@@ -138,9 +139,15 @@ function multi.InitSystemThreadErrorHandler()
temp.statusconnector:Fire(unpack(({__StatusLinda:receive(nil, temp.Id)})[2]))
end
if status == "done" or temp.returns:get("returns") then
returns = ({temp.returns:receive(0, "returns")})[2]
livingThreads[temp.Id] = {false, temp.Name}
temp.alive = false
temp.OnDeath:Fire(unpack(({temp.returns:receive(0, "returns")})[2]))
if returns[1] == false then
temp.OnError:Fire(temp, returns[2])
else
table.remove(returns,1)
temp.OnDeath:Fire(unpack(returns))
end
GLOBAL["__THREADS__"] = livingThreads
table.remove(threads, i)
elseif status == "running" then
@@ -148,11 +155,7 @@ function multi.InitSystemThreadErrorHandler()
elseif status == "waiting" then
--
elseif status == "error" then
livingThreads[temp.Id] = {false, temp.Name}
temp.alive = false
temp.OnError:Fire(temp,unpack(temp.returns:receive(0,"returns") or {"Thread Killed!"}))
GLOBAL["__THREADS__"] = livingThreads
table.remove(threads, i)
-- The thread never really errors, we handle this through our linda object
elseif status == "cancelled" then
livingThreads[temp.Id] = {false, temp.Name}
temp.alive = false
@@ -168,7 +171,7 @@ function multi.InitSystemThreadErrorHandler()
end
end
end
end)
end).OnError(print)
end
multi.print("Integrated Lanes Threading!")
+10 -7
View File
@@ -50,7 +50,6 @@ function multi:newSystemThreadedQueue(name)
GLOBAL[name or "_"] = c
return c
end
function multi:newSystemThreadedTable(name)
local c = {}
function c:init()
@@ -69,7 +68,6 @@ if not setfenv then
end
end
end
function multi:newSystemThreadedJobQueue(n)
local c = {}
c.cores = n or THREAD.getCores()*2
@@ -96,7 +94,6 @@ function multi:newSystemThreadedJobQueue(n)
return jid-1
end
function c:isEmpty()
print(#jobs)
return #jobs == 0
end
local nFunc = 0
@@ -116,7 +113,6 @@ function multi:newSystemThreadedJobQueue(n)
link = c.OnJobCompleted(function(jid,...)
if id==jid then
rets = {...}
link:Destroy()
end
end)
return thread.hold(function()
@@ -127,7 +123,7 @@ function multi:newSystemThreadedJobQueue(n)
end,holup),name
end
for i=1,c.cores do
thread:newthread("PesudoThreadedJobQueue_"..i,function()
thread:newThread("PesudoThreadedJobQueue_"..i,function()
while true do
thread.yield()
if #jobs>0 then
@@ -137,7 +133,14 @@ function multi:newSystemThreadedJobQueue(n)
thread.sleep(.05)
end
end
end)
end).OnError(print)
end
return c
end
end
function multi:newSystemThreadedConnection(name)
local conn = multi.newConnection()
conn.init = function(self) return self end
GLOBAL[name or "_"] = conn
return conn
end
+6
View File
@@ -67,6 +67,12 @@ function multi:newSystemThread(name,func,...)
THREAD_ID = id,
thread = thread
}
if GLOBAL["__env"] then
for i,v in pairs(GLOBAL["__env"]) do
env[i] = v
end
end
for i = 1,#tab do
env[tab[i]] = _G[tab[i]]
+2 -2
View File
@@ -101,8 +101,8 @@ local function INIT(thread)
THREAD.sleep = thread.sleep
THREAD.hold = thread.hold
function THREAD.setENV(env)
function THREAD.setENV(env)
GLOBAL["__env"] = env
end