Jobqueues lvl up

This commit is contained in:
Ryan Ward 2020-02-14 15:38:00 -05:00
parent ead2fd6f2c
commit ebe87ed69a
6 changed files with 46 additions and 43 deletions

View File

@ -1,4 +1,4 @@
# multi Version: 14.0.0 Bug fixes and cool new features added (See changes.md) # multi Version: 14.1.0 System threaded functions (See changes.md)
Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and ill look into it! Found an issue? Please [submit it](https://github.com/rayaman/multi/issues) and ill look into it!

View File

@ -1,5 +0,0 @@
MAIN: Love2d support is updated to 11.1
May be bugs in supporting libraries, but the multitasking library is fully updated.
The GuiManager may have a bug or 2, but I haven't found any ground breaking bugs that haven't been fixed

View File

@ -1742,7 +1742,7 @@ function multi.initThreads(justThreads)
for i=#threads,1,-1 do for i=#threads,1,-1 do
if not threads[i].__started then if not threads[i].__started then
if coroutine.running() ~= threads[i].thread then if coroutine.running() ~= threads[i].thread then
_,ret,r1,r2,r3,r4,r5,r6=coroutine.resume(threads[i].thread,t0,t1,t2,t3,t4,t5,t6) _,ret,r1,r2,r3,r4,r5,r6=coroutine.resume(threads[i].thread,unpack(threads[i].startArgs))
CheckRets(i) CheckRets(i)
end end
threads[i].__started = true threads[i].__started = true

View File

@ -80,6 +80,7 @@ function multi:newSystemThreadedJobQueue(n)
function c:pushJob(name,...) function c:pushJob(name,...)
queueJob:push{name,jid,{...}} queueJob:push{name,jid,{...}}
jid = jid + 1 jid = jid + 1
return jid-1
end end
multi:newThread("JobQueueManager",function() multi:newThread("JobQueueManager",function()
while true do while true do

View File

@ -1,12 +0,0 @@
package.path="?/init.lua;?.lua;"..package.path
multi = require("multi")
local GLOBAL, THREAD = require("multi.integration.lanesManager").init()
nGLOBAL = require("multi.integration.networkManager").init()
multi:nodeManager(12345) -- Host a node manager on port: 12345
print("Node Manager Running...")
settings = {
priority = 0, -- 1 or 2
protect = false,
}
multi:mainloop(settings)
-- Thats all you need to run the node manager, everything else is done automatically

View File

@ -1,25 +1,44 @@
package.path="?/init.lua;?.lua;"..package.path package.path="?.lua;?/init.lua;?.lua;"..package.path
multi,thread = require("multi"):init() local multi,thread = require("multi"):init()
--GLOBAL,THREAD = require("multi.integration.lanesManager"):init() GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
-- local co = 0 local test = multi:newSystemThreadedJobQueue(4)
-- multi.OnLoad(function() local nFunc = 0
-- print("Code Loaded!") function test:newFunction(name,func,holup) -- This registers with the queue
-- end) if type(name)=="function" then
multi.OnExit(function(n) holup = func
print("Code Exited!") func = name
end) name = "JQFunction_"..nFunc
-- multi:newThread(function() end
-- t = os.clock() local ref = self
-- while true do nFunc = nFunc + 1
-- thread.skip() ref:registerFunction(name,func)
-- co = co + 1 return thread:newFunction(function(...)
-- end local id = ref:pushJob(name,...)
-- end) local link
-- multi:setTimeout(function() local rets
-- os.exit() link = ref.OnJobCompleted(function(jid,...)
-- end,5) if id==jid then
multi:benchMark(1):OnBench(function(...) rets = {...}
print(...) link:Remove()
os.exit() end
end) end)
return thread.hold(function()
if rets then
return unpack(rets)
end
end)
end,holup)
end
func = test:newFunction("test",function(a)
test2()
return a..a
end,true)
func2 = test:newFunction("test2",function(a)
print("ooo")
end,true)
print(func("1"))
print(func("Hello"))
print(func("sigh"))
print(#test.OnJobCompleted.connections)
os.exit()
multi:mainloop() multi:mainloop()