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 __SleepingLinda = lanes.linda() -- handles sleeping 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 started = false
|
||||
local livingThreads = {}
|
||||
@ -110,12 +112,17 @@ function multi.InitSystemThreadErrorHandler()
|
||||
started = true
|
||||
thread:newThread("SystemThreadScheduler",function()
|
||||
local threads = multi.SystemThreads
|
||||
local _,data,status,push,temp
|
||||
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.
|
||||
local _,data = __ConsoleLinda:receive(0, "Q")
|
||||
thread.yield()
|
||||
_,data = __ConsoleLinda:receive(0, "Q")
|
||||
for i = #threads, 1, -1 do
|
||||
local status = threads[i].thread.status
|
||||
local temp = threads[i]
|
||||
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
|
||||
livingThreads[temp.Id] = {false, temp.Name}
|
||||
temp.alive = false
|
||||
|
||||
@ -28,7 +28,7 @@ local function getOS()
|
||||
return "unix"
|
||||
end
|
||||
end
|
||||
local function INIT(__GlobalLinda,__SleepingLinda)
|
||||
local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
|
||||
local THREAD = {}
|
||||
THREAD.Priority_Core = 3
|
||||
THREAD.Priority_High = 2
|
||||
@ -90,6 +90,10 @@ local function INIT(__GlobalLinda,__SleepingLinda)
|
||||
function THREAD.getID()
|
||||
return THREAD_ID
|
||||
end
|
||||
function THREAD.pushStatus(...)
|
||||
local args = {...}
|
||||
__StatusLinda:send(nil,THREAD_ID, args)
|
||||
end
|
||||
_G.THREAD_ID = 0
|
||||
function THREAD.sleep(n)
|
||||
math.randomseed(os.time())
|
||||
@ -115,6 +119,6 @@ local function INIT(__GlobalLinda,__SleepingLinda)
|
||||
})
|
||||
return GLOBAL, THREAD
|
||||
end
|
||||
return {init = function(g,s)
|
||||
return INIT(g,s)
|
||||
return {init = function(g,s,st)
|
||||
return INIT(g,s,st)
|
||||
end}
|
||||
45
test.lua
45
test.lua
@ -2,17 +2,46 @@ package.path = "./?/init.lua;"..package.path
|
||||
multi, thread = require("multi"):init()
|
||||
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
||||
|
||||
THREAD:newSystemThread("Test",function()
|
||||
print("In a thread...")
|
||||
thread:newThread(function()
|
||||
func = THREAD:newFunction(function(count)
|
||||
print("Starting Status test: ",count)
|
||||
local a = 0
|
||||
while true do
|
||||
THREAD.sleep(1)
|
||||
print("In thread")
|
||||
a = a + 1
|
||||
THREAD.sleep(.1)
|
||||
THREAD.pushStatus(a,count)
|
||||
if a == count then break 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)
|
||||
|
||||
multi:newTLoop(function()
|
||||
print("...")
|
||||
end,1)
|
||||
|
||||
-- local proc = multi:newProcessor("Test")
|
||||
-- local proc2 = multi:newProcessor("Test2")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user