THREAD.pushStatus for lanes works, todo love
This commit is contained in:
parent
79f58a79f9
commit
d30ee3788e
@ -48,7 +48,9 @@ end
|
|||||||
local __GlobalLinda = lanes.linda() -- handles global stuff
|
local __GlobalLinda = lanes.linda() -- handles global stuff
|
||||||
local __SleepingLinda = lanes.linda() -- handles sleeping stuff
|
local __SleepingLinda = lanes.linda() -- handles sleeping stuff
|
||||||
local __ConsoleLinda = lanes.linda() -- handles console stuff
|
local __ConsoleLinda = lanes.linda() -- handles console stuff
|
||||||
local GLOBAL,THREAD = require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda)
|
local __StatusLinda = lanes.linda() -- handles pushstatus for stfunctions
|
||||||
|
|
||||||
|
local GLOBAL,THREAD = require("multi.integration.lanesManager.threads").init(__GlobalLinda, __SleepingLinda, __StatusLinda)
|
||||||
local count = 1
|
local count = 1
|
||||||
local started = false
|
local started = false
|
||||||
local livingThreads = {}
|
local livingThreads = {}
|
||||||
@ -110,12 +112,17 @@ function multi.InitSystemThreadErrorHandler()
|
|||||||
started = true
|
started = true
|
||||||
thread:newThread("SystemThreadScheduler",function()
|
thread:newThread("SystemThreadScheduler",function()
|
||||||
local threads = multi.SystemThreads
|
local threads = multi.SystemThreads
|
||||||
|
local _,data,status,push,temp
|
||||||
while true do
|
while true do
|
||||||
thread.sleep(.005) -- switching states often takes a huge hit on performance. half a second to tell me there is an error is good enough.
|
thread.yield()
|
||||||
local _,data = __ConsoleLinda:receive(0, "Q")
|
_,data = __ConsoleLinda:receive(0, "Q")
|
||||||
for i = #threads, 1, -1 do
|
for i = #threads, 1, -1 do
|
||||||
local status = threads[i].thread.status
|
temp = threads[i]
|
||||||
local temp = threads[i]
|
status = temp.thread.status
|
||||||
|
push = __StatusLinda:get(temp.Id)
|
||||||
|
if push then
|
||||||
|
temp.statusconnector:Fire(unpack(({__StatusLinda:receive(nil, temp.Id)})[2]))
|
||||||
|
end
|
||||||
if status == "done" or temp.returns:get("returns") then
|
if status == "done" or temp.returns:get("returns") then
|
||||||
livingThreads[temp.Id] = {false, temp.Name}
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
temp.alive = false
|
temp.alive = false
|
||||||
|
|||||||
@ -28,7 +28,7 @@ local function getOS()
|
|||||||
return "unix"
|
return "unix"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function INIT(__GlobalLinda,__SleepingLinda)
|
local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
|
||||||
local THREAD = {}
|
local THREAD = {}
|
||||||
THREAD.Priority_Core = 3
|
THREAD.Priority_Core = 3
|
||||||
THREAD.Priority_High = 2
|
THREAD.Priority_High = 2
|
||||||
@ -90,6 +90,10 @@ local function INIT(__GlobalLinda,__SleepingLinda)
|
|||||||
function THREAD.getID()
|
function THREAD.getID()
|
||||||
return THREAD_ID
|
return THREAD_ID
|
||||||
end
|
end
|
||||||
|
function THREAD.pushStatus(...)
|
||||||
|
local args = {...}
|
||||||
|
__StatusLinda:send(nil,THREAD_ID, args)
|
||||||
|
end
|
||||||
_G.THREAD_ID = 0
|
_G.THREAD_ID = 0
|
||||||
function THREAD.sleep(n)
|
function THREAD.sleep(n)
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
@ -115,6 +119,6 @@ local function INIT(__GlobalLinda,__SleepingLinda)
|
|||||||
})
|
})
|
||||||
return GLOBAL, THREAD
|
return GLOBAL, THREAD
|
||||||
end
|
end
|
||||||
return {init = function(g,s)
|
return {init = function(g,s,st)
|
||||||
return INIT(g,s)
|
return INIT(g,s,st)
|
||||||
end}
|
end}
|
||||||
45
test.lua
45
test.lua
@ -2,18 +2,47 @@ package.path = "./?/init.lua;"..package.path
|
|||||||
multi, thread = require("multi"):init()
|
multi, thread = require("multi"):init()
|
||||||
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
||||||
|
|
||||||
THREAD:newSystemThread("Test",function()
|
thread:newThread(function()
|
||||||
print("In a thread...")
|
func = THREAD:newFunction(function(count)
|
||||||
|
print("Starting Status test: ",count)
|
||||||
|
local a = 0
|
||||||
while true do
|
while true do
|
||||||
THREAD.sleep(1)
|
a = a + 1
|
||||||
print("In thread")
|
THREAD.sleep(.1)
|
||||||
|
THREAD.pushStatus(a,count)
|
||||||
|
if a == count then break end
|
||||||
end
|
end
|
||||||
|
return "Done"
|
||||||
|
end)
|
||||||
|
local ret = func(10)
|
||||||
|
local ret2 = func(15)
|
||||||
|
local ret3 = func(20)
|
||||||
|
local s1,s2,s3 = 0,0,0
|
||||||
|
ret.OnError(function(...)
|
||||||
|
print("Error:",...)
|
||||||
|
end)
|
||||||
|
ret2.OnError(function(...)
|
||||||
|
print("Error:",...)
|
||||||
|
end)
|
||||||
|
ret3.OnError(function(...)
|
||||||
|
print("Error:",...)
|
||||||
|
end)
|
||||||
|
ret.OnStatus(function(part,whole)
|
||||||
|
s1 = math.ceil((part/whole)*1000)/10
|
||||||
|
print(s1)
|
||||||
|
end)
|
||||||
|
ret2.OnStatus(function(part,whole)
|
||||||
|
s2 = math.ceil((part/whole)*1000)/10
|
||||||
|
print(s2)
|
||||||
|
end)
|
||||||
|
ret3.OnStatus(function(part,whole)
|
||||||
|
s3 = math.ceil((part/whole)*1000)/10
|
||||||
|
print(s3)
|
||||||
|
end)
|
||||||
|
local err, timeout = thread.hold(ret.OnReturn + ret2.OnReturn + ret3.OnReturn)
|
||||||
|
print("Done")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
multi:newTLoop(function()
|
|
||||||
print("...")
|
|
||||||
end,1)
|
|
||||||
|
|
||||||
-- local proc = multi:newProcessor("Test")
|
-- local proc = multi:newProcessor("Test")
|
||||||
-- local proc2 = multi:newProcessor("Test2")
|
-- local proc2 = multi:newProcessor("Test2")
|
||||||
-- local proc3 = proc2:newProcessor("Test3")
|
-- local proc3 = proc2:newProcessor("Test3")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user