Issue with love2d system threaded functions pushstatus fixed
This commit is contained in:
parent
d30ee3788e
commit
568c95fa73
@ -948,6 +948,7 @@ function multi:newProcessor(name,nothread)
|
|||||||
c.threads = {}
|
c.threads = {}
|
||||||
c.startme = {}
|
c.startme = {}
|
||||||
c.parent = self
|
c.parent = self
|
||||||
|
|
||||||
local handler = c:createHandler(c.threads,c.startme)
|
local handler = c:createHandler(c.threads,c.startme)
|
||||||
|
|
||||||
c.process = self:newLoop(function()
|
c.process = self:newLoop(function()
|
||||||
@ -1533,7 +1534,7 @@ co_status = {
|
|||||||
["suspended"] = function(thd,ref,task,i,th)
|
["suspended"] = function(thd,ref,task,i,th)
|
||||||
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 then -- The rework makes this necessary
|
if ret ~= CMD and _ ~= nil then -- The rework makes this necessary
|
||||||
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
|
||||||
@ -2118,4 +2119,4 @@ else
|
|||||||
multi.m.sentinel = newproxy(true)
|
multi.m.sentinel = newproxy(true)
|
||||||
getmetatable(multi.m.sentinel).__gc = multi.m.onexit
|
getmetatable(multi.m.sentinel).__gc = multi.m.onexit
|
||||||
end
|
end
|
||||||
return multi
|
return multi
|
||||||
@ -62,20 +62,28 @@ function multi:newSystemThread(name,func,...)
|
|||||||
GLOBAL["__THREAD_COUNT"] = THREAD_ID
|
GLOBAL["__THREAD_COUNT"] = THREAD_ID
|
||||||
THREAD_ID=THREAD_ID + 1
|
THREAD_ID=THREAD_ID + 1
|
||||||
thread:newThread(function()
|
thread:newThread(function()
|
||||||
thread.hold(function()
|
if name:find("TempSystemThread") then
|
||||||
return not c.thread:isRunning()
|
local status_channel = love.thread.getChannel("__"..c.ID.."__MULTI__STATUS_CHANNEL__")
|
||||||
end)
|
thread.hold(function()
|
||||||
print("Thread: "..name.." finished executing...")
|
-- While the thread is running we might as well do something in the loop
|
||||||
|
local status = status_channel
|
||||||
|
if status:peek()~=nil then
|
||||||
|
c.statusconnector:Fire(unpack(status:pop()))
|
||||||
|
end
|
||||||
|
return not c.thread:isRunning()
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
thread.hold(function()
|
||||||
|
return not c.thread:isRunning()
|
||||||
|
end)
|
||||||
|
end
|
||||||
-- If the thread is not running let's handle that.
|
-- If the thread is not running let's handle that.
|
||||||
local thread_err = c.thread:getError()
|
local thread_err = c.thread:getError()
|
||||||
if thread_err == "Thread Killed!\1" then
|
if thread_err == "Thread Killed!\1" then
|
||||||
print("Killed...")
|
|
||||||
c.OnDeath:Fire(c,"Thread Killed!")
|
c.OnDeath:Fire(c,"Thread Killed!")
|
||||||
elseif thread_err then
|
elseif thread_err then
|
||||||
print("Error...",thread_err)
|
|
||||||
c.OnError:Fire(c,thread_err)
|
c.OnError:Fire(c,thread_err)
|
||||||
elseif c.stab.returns then
|
elseif c.stab.returns then
|
||||||
print("Returns",unpack(c.stab.returns))
|
|
||||||
c.OnDeath:Fire(c,unpack(c.stab.returns))
|
c.OnDeath:Fire(c,unpack(c.stab.returns))
|
||||||
c.stab.returns = nil
|
c.stab.returns = nil
|
||||||
end
|
end
|
||||||
@ -85,18 +93,20 @@ end
|
|||||||
|
|
||||||
function THREAD:newFunction(func)
|
function THREAD:newFunction(func)
|
||||||
return thread:newFunctionBase(function(...)
|
return thread:newFunctionBase(function(...)
|
||||||
return multi:newSystemThread("TempSystemThread",func,...)
|
return multi:newSystemThread("TempSystemThread"..THREAD_ID,func,...)
|
||||||
end)()
|
end)()
|
||||||
end
|
end
|
||||||
|
|
||||||
THREAD.newSystemThread = multi.newSystemThread
|
THREAD.newSystemThread = multi.newSystemThread
|
||||||
|
|
||||||
function love.threaderror(thread, errorstr)
|
function love.threaderror(thread, errorstr)
|
||||||
print("Thread error!\n"..errorstr)
|
mulit.print("Thread error!\n"..errorstr)
|
||||||
end
|
end
|
||||||
|
|
||||||
multi.integration.GLOBAL = GLOBAL
|
multi.integration.GLOBAL = GLOBAL
|
||||||
multi.integration.THREAD = THREAD
|
multi.integration.THREAD = THREAD
|
||||||
require("multi.integration.loveManager.extensions")
|
require("multi.integration.loveManager.extensions")
|
||||||
print("Integrated Love Threading!")
|
mulit.print("Integrated Love Threading!")
|
||||||
return {init=function()
|
return {init=function()
|
||||||
return GLOBAL,THREAD
|
return GLOBAL,THREAD
|
||||||
end}
|
end}
|
||||||
@ -24,6 +24,7 @@ SOFTWARE.
|
|||||||
require("love.timer")
|
require("love.timer")
|
||||||
require("love.system")
|
require("love.system")
|
||||||
require("love.data")
|
require("love.data")
|
||||||
|
require("love.thread")
|
||||||
local socket = require("socket")
|
local socket = require("socket")
|
||||||
local multi, thread = require("multi").init()
|
local multi, thread = require("multi").init()
|
||||||
local threads = {}
|
local threads = {}
|
||||||
@ -94,6 +95,11 @@ end
|
|||||||
function threads.kill()
|
function threads.kill()
|
||||||
error("Thread Killed!\1")
|
error("Thread Killed!\1")
|
||||||
end
|
end
|
||||||
|
function THREAD.pushStatus(...)
|
||||||
|
local status_channel = love.thread.getChannel("__"..__THREADID__.."__MULTI__STATUS_CHANNEL__")
|
||||||
|
local args = {...}
|
||||||
|
status_channel:push(__THREADID__, args)
|
||||||
|
end
|
||||||
function threads.getThreads()
|
function threads.getThreads()
|
||||||
local t = {}
|
local t = {}
|
||||||
for i=1,GLOBAL["__THREAD_COUNT"] do
|
for i=1,GLOBAL["__THREAD_COUNT"] do
|
||||||
|
|||||||
@ -32,7 +32,7 @@ if multi.integration then
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local GLOBAL, THREAD = require("multi.integration.pesudoManager.threads"):init()
|
local GLOBAL, THREAD = require("multi.integration.pesudoManager.threads"):init(thread)
|
||||||
|
|
||||||
function multi:canSystemThread() -- We are emulating system threading
|
function multi:canSystemThread() -- We are emulating system threading
|
||||||
return true
|
return true
|
||||||
@ -75,6 +75,7 @@ function multi:newSystemThread(name,func,...)
|
|||||||
end)
|
end)
|
||||||
id = id + 1
|
id = id + 1
|
||||||
end
|
end
|
||||||
|
THREAD.newSystemThread = multi.newSystemThread
|
||||||
-- System threads as implemented here cannot share memory, but use a message passing system.
|
-- System threads as implemented here cannot share memory, but use a message passing system.
|
||||||
-- An isolated thread allows us to mimic that behavior so if access data from the "main" thread happens things will not work. This behavior is in line with how the system threading works
|
-- An isolated thread allows us to mimic that behavior so if access data from the "main" thread happens things will not work. This behavior is in line with how the system threading works
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ local function getOS()
|
|||||||
return "unix"
|
return "unix"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function INIT(env)
|
local function INIT(env,thread)
|
||||||
local THREAD = {}
|
local THREAD = {}
|
||||||
local GLOBAL = {}
|
local GLOBAL = {}
|
||||||
THREAD.Priority_Core = 3
|
THREAD.Priority_Core = 3
|
||||||
@ -45,7 +45,6 @@ local function INIT(env)
|
|||||||
return GLOBAL[name]
|
return GLOBAL[name]
|
||||||
end
|
end
|
||||||
function THREAD.waitFor(name)
|
function THREAD.waitFor(name)
|
||||||
print("Waiting",thread)
|
|
||||||
return thread.hold(function() return GLOBAL[name] end)
|
return thread.hold(function() return GLOBAL[name] end)
|
||||||
end
|
end
|
||||||
if getOS() == "windows" then
|
if getOS() == "windows" then
|
||||||
@ -69,6 +68,7 @@ local function INIT(env)
|
|||||||
function THREAD.getThreads()
|
function THREAD.getThreads()
|
||||||
return {}--GLOBAL.__THREADS__
|
return {}--GLOBAL.__THREADS__
|
||||||
end
|
end
|
||||||
|
THREAD.pushstatus = thread.pushstatus
|
||||||
if os.getOS() == "windows" then
|
if os.getOS() == "windows" then
|
||||||
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
|
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
|
||||||
else
|
else
|
||||||
@ -83,6 +83,7 @@ local function INIT(env)
|
|||||||
function THREAD.getID()
|
function THREAD.getID()
|
||||||
return GLOBAL["$THREAD_ID"]
|
return GLOBAL["$THREAD_ID"]
|
||||||
end
|
end
|
||||||
|
THREAD.pushstatus
|
||||||
function THREAD.sleep(n)
|
function THREAD.sleep(n)
|
||||||
thread.sleep(n)
|
thread.sleep(n)
|
||||||
end
|
end
|
||||||
@ -91,6 +92,6 @@ local function INIT(env)
|
|||||||
end
|
end
|
||||||
return GLOBAL, THREAD
|
return GLOBAL, THREAD
|
||||||
end
|
end
|
||||||
return {init = function()
|
return {init = function(thread)
|
||||||
return INIT()
|
return INIT(nil,thread)
|
||||||
end}
|
end}
|
||||||
74
test.lua
74
test.lua
@ -2,45 +2,41 @@ 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:newThread(function()
|
func = THREAD:newFunction(function(count)
|
||||||
func = THREAD:newFunction(function(count)
|
print("Starting Status test: ",count)
|
||||||
print("Starting Status test: ",count)
|
local a = 0
|
||||||
local a = 0
|
while true do
|
||||||
while true do
|
a = a + 1
|
||||||
a = a + 1
|
THREAD.sleep(.1)
|
||||||
THREAD.sleep(.1)
|
THREAD.pushStatus(a,count)
|
||||||
THREAD.pushStatus(a,count)
|
if a == count then break end
|
||||||
if a == count then break end
|
end
|
||||||
end
|
return "Done"
|
||||||
return "Done"
|
end)
|
||||||
end)
|
local ret = func(10)
|
||||||
local ret = func(10)
|
local ret2 = func(15)
|
||||||
local ret2 = func(15)
|
local ret3 = func(20)
|
||||||
local ret3 = func(20)
|
local s1,s2,s3 = 0,0,0
|
||||||
local s1,s2,s3 = 0,0,0
|
ret.OnError(function(...)
|
||||||
ret.OnError(function(...)
|
print("Error:",...)
|
||||||
print("Error:",...)
|
end)
|
||||||
end)
|
ret2.OnError(function(...)
|
||||||
ret2.OnError(function(...)
|
print("Error:",...)
|
||||||
print("Error:",...)
|
end)
|
||||||
end)
|
ret3.OnError(function(...)
|
||||||
ret3.OnError(function(...)
|
print("Error:",...)
|
||||||
print("Error:",...)
|
end)
|
||||||
end)
|
ret.OnStatus(function(part,whole)
|
||||||
ret.OnStatus(function(part,whole)
|
s1 = math.ceil((part/whole)*1000)/10
|
||||||
s1 = math.ceil((part/whole)*1000)/10
|
print(s1)
|
||||||
print(s1)
|
end)
|
||||||
end)
|
ret2.OnStatus(function(part,whole)
|
||||||
ret2.OnStatus(function(part,whole)
|
s2 = math.ceil((part/whole)*1000)/10
|
||||||
s2 = math.ceil((part/whole)*1000)/10
|
print(s2)
|
||||||
print(s2)
|
end)
|
||||||
end)
|
ret3.OnStatus(function(part,whole)
|
||||||
ret3.OnStatus(function(part,whole)
|
s3 = math.ceil((part/whole)*1000)/10
|
||||||
s3 = math.ceil((part/whole)*1000)/10
|
print(s3)
|
||||||
print(s3)
|
|
||||||
end)
|
|
||||||
local err, timeout = thread.hold(ret.OnReturn + ret2.OnReturn + ret3.OnReturn)
|
|
||||||
print("Done")
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- local proc = multi:newProcessor("Test")
|
-- local proc = multi:newProcessor("Test")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user