Fixed tests on lanes and pseudo threading, todo fix love2d threading
This commit is contained in:
parent
8d843a5958
commit
91561f7f24
@ -85,7 +85,7 @@ Allows the user to have multi auto set priorities (Requires chronos). Also adds
|
|||||||
Added
|
Added
|
||||||
---
|
---
|
||||||
- thread.defer(func) -- When using a co-routine thread or co-routine threaded function, defer will call it's function at the end of the the threads life through normal execution or an error. In the case of a function, when the function returns or errors.
|
- thread.defer(func) -- When using a co-routine thread or co-routine threaded function, defer will call it's function at the end of the the threads life through normal execution or an error. In the case of a function, when the function returns or errors.
|
||||||
- multi:setTaskDelay(delay), Tasks which are now tied to a processor can have an optional delay between the execution between each task. Useful perhaps for rate limiting. Without a delay all grouped tasks will be handled in one step.
|
- multi:setTaskDelay(delay), Tasks which are now tied to a processor can have an optional delay between the execution between each task. Useful perhaps for rate limiting. Without a delay all grouped tasks will be handled in one step. `delay` can be a function as well and will be processed as if thread.hold was called.
|
||||||
- processor's now have a boost function which causes it to run its processes the number of times specified in the `boost(count)` function
|
- processor's now have a boost function which causes it to run its processes the number of times specified in the `boost(count)` function
|
||||||
- thread.hold will now use a custom hold method for objects with a `Hold` method. This is called like `obj:Hold(opt)`. The only argument passed is the optional options table that thread.hold can pass. There is an exception for connection objects. While they do contain a Hold method, the Hold method isn't used and is there for proxy objects, though they can be used in non proxy/thread situations. Hold returns all the arguments that the connection object was fired with.
|
- thread.hold will now use a custom hold method for objects with a `Hold` method. This is called like `obj:Hold(opt)`. The only argument passed is the optional options table that thread.hold can pass. There is an exception for connection objects. While they do contain a Hold method, the Hold method isn't used and is there for proxy objects, though they can be used in non proxy/thread situations. Hold returns all the arguments that the connection object was fired with.
|
||||||
- shared_table = STP:newSharedTable(tbl_name) -- Allows you to create a shared table that all system threads in a process have access to. Returns a reference to that table for use on the main thread. Sets `_G[tbl_name]` on the system threads so you can access it there.
|
- shared_table = STP:newSharedTable(tbl_name) -- Allows you to create a shared table that all system threads in a process have access to. Returns a reference to that table for use on the main thread. Sets `_G[tbl_name]` on the system threads so you can access it there.
|
||||||
|
|||||||
36
init.lua
36
init.lua
@ -189,6 +189,7 @@ local optimization_stats = {}
|
|||||||
local ignoreconn = true
|
local ignoreconn = true
|
||||||
local empty_func = function() end
|
local empty_func = function() end
|
||||||
function multi:newConnection(protect,func,kill)
|
function multi:newConnection(protect,func,kill)
|
||||||
|
local processor = self
|
||||||
local c={}
|
local c={}
|
||||||
local lock = false
|
local lock = false
|
||||||
local fast = {}
|
local fast = {}
|
||||||
@ -380,7 +381,7 @@ function multi:newConnection(protect,func,kill)
|
|||||||
end
|
end
|
||||||
if kill then
|
if kill then
|
||||||
table.insert(kills,i)
|
table.insert(kills,i)
|
||||||
multi:newTask(function()
|
processor:newTask(function()
|
||||||
for _, k in pairs(kills) do
|
for _, k in pairs(kills) do
|
||||||
table.remove(kills, _)
|
table.remove(kills, _)
|
||||||
table.remove(fast, k)
|
table.remove(fast, k)
|
||||||
@ -418,7 +419,7 @@ function multi:newConnection(protect,func,kill)
|
|||||||
fast[i](...)
|
fast[i](...)
|
||||||
if kill then
|
if kill then
|
||||||
table.insert(kills,i)
|
table.insert(kills,i)
|
||||||
multi:newTask(function()
|
processor:newTask(function()
|
||||||
for _, k in pairs(kills) do
|
for _, k in pairs(kills) do
|
||||||
table.remove(kills, _)
|
table.remove(kills, _)
|
||||||
table.remove(fast, k)
|
table.remove(fast, k)
|
||||||
@ -1147,9 +1148,8 @@ function multi:newProcessor(name, nothread, priority)
|
|||||||
|
|
||||||
function c:boost(count)
|
function c:boost(count)
|
||||||
boost = count or 1
|
boost = count or 1
|
||||||
end
|
if boost > 1 then
|
||||||
|
self.run = function()
|
||||||
function c.run()
|
|
||||||
if not Active then return end
|
if not Active then return end
|
||||||
for i=1,boost do
|
for i=1,boost do
|
||||||
c:uManager(true)
|
c:uManager(true)
|
||||||
@ -1157,6 +1157,22 @@ function multi:newProcessor(name, nothread, priority)
|
|||||||
end
|
end
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
self.run = function()
|
||||||
|
if not Active then return end
|
||||||
|
c:uManager(true)
|
||||||
|
handler()
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function c.run()
|
||||||
|
if not Active then return end
|
||||||
|
c:uManager(true)
|
||||||
|
handler()
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
|
||||||
function c.isActive()
|
function c.isActive()
|
||||||
return Active
|
return Active
|
||||||
@ -1178,8 +1194,12 @@ function multi:newProcessor(name, nothread, priority)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function c:setTaskDelay(delay)
|
function c:setTaskDelay(delay)
|
||||||
|
if type(delay) == "function" then
|
||||||
|
task_delay = delay
|
||||||
|
else
|
||||||
task_delay = tonumber(delay) or 0
|
task_delay = tonumber(delay) or 0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
c:newThread("Task Handler", function()
|
c:newThread("Task Handler", function()
|
||||||
local self = multi:getCurrentProcess()
|
local self = multi:getCurrentProcess()
|
||||||
@ -1193,7 +1213,7 @@ function multi:newProcessor(name, nothread, priority)
|
|||||||
thread.hold(task_holder)
|
thread.hold(task_holder)
|
||||||
end
|
end
|
||||||
if task_delay~=0 then
|
if task_delay~=0 then
|
||||||
thread.sleep(task_delay)
|
thread.hold(task_delay)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end).OnError(multi.error)
|
end).OnError(multi.error)
|
||||||
@ -2481,12 +2501,14 @@ function multi.success(...)
|
|||||||
io.write("\x1b[92mSUCCESS:\x1b[0m " .. table.concat(t," ") .. "\n")
|
io.write("\x1b[92mSUCCESS:\x1b[0m " .. table.concat(t," ") .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Old things for compatability
|
||||||
multi.GetType = multi.getType
|
multi.GetType = multi.getType
|
||||||
multi.IsPaused = multi.isPaused
|
multi.IsPaused = multi.isPaused
|
||||||
multi.IsActive = multi.isActive
|
multi.IsActive = multi.isActive
|
||||||
multi.Reallocate = multi.Reallocate
|
multi.Reallocate = multi.reallocate
|
||||||
multi.ConnectFinal = multi.connectFinal
|
multi.ConnectFinal = multi.connectFinal
|
||||||
multi.ResetTime = multi.SetTime
|
multi.ResetTime = multi.SetTime
|
||||||
|
multi.setTime = multi.SetTime
|
||||||
multi.IsDone = multi.isDone
|
multi.IsDone = multi.isDone
|
||||||
multi.SetName = multi.setName
|
multi.SetName = multi.setName
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,6 @@ function multi:newSystemThread(name, func, ...)
|
|||||||
THREAD = THREAD,
|
THREAD = THREAD,
|
||||||
THREAD_NAME = tostring(name),
|
THREAD_NAME = tostring(name),
|
||||||
__THREADNAME__ = tostring(name),
|
__THREADNAME__ = tostring(name),
|
||||||
test = "testing",
|
|
||||||
THREAD_ID = id,
|
THREAD_ID = id,
|
||||||
thread = thread,
|
thread = thread,
|
||||||
multi = multi,
|
multi = multi,
|
||||||
|
|||||||
@ -60,6 +60,7 @@ function multi:newProxy(list)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
if not(self.is_init) then
|
if not(self.is_init) then
|
||||||
|
THREAD.sleep(.3)
|
||||||
self.is_init = true
|
self.is_init = true
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
self.proxy_link = "PL" .. multi.randomString(12)
|
self.proxy_link = "PL" .. multi.randomString(12)
|
||||||
@ -92,8 +93,6 @@ function multi:newProxy(list)
|
|||||||
local sref = table.remove(data, 1)
|
local sref = table.remove(data, 1)
|
||||||
local ret
|
local ret
|
||||||
|
|
||||||
print(_G[list[0]], func)
|
|
||||||
|
|
||||||
if sref then
|
if sref then
|
||||||
ret = {_G[list[0]][func](_G[list[0]], multi.unpack(data))}
|
ret = {_G[list[0]][func](_G[list[0]], multi.unpack(data))}
|
||||||
else
|
else
|
||||||
@ -120,6 +119,7 @@ function multi:newProxy(list)
|
|||||||
end)
|
end)
|
||||||
return self
|
return self
|
||||||
else
|
else
|
||||||
|
THREAD.sleep(.3)
|
||||||
local function copy(obj)
|
local function copy(obj)
|
||||||
if type(obj) ~= 'table' then return obj end
|
if type(obj) ~= 'table' then return obj end
|
||||||
local res = {}
|
local res = {}
|
||||||
@ -145,7 +145,6 @@ function multi:newProxy(list)
|
|||||||
setmetatable(v[2],getmetatable(multi:newConnection()))
|
setmetatable(v[2],getmetatable(multi:newConnection()))
|
||||||
else
|
else
|
||||||
self[v] = thread:newFunction(function(self,...)
|
self[v] = thread:newFunction(function(self,...)
|
||||||
multi.print("Pushing: " .. v)
|
|
||||||
if self == me then
|
if self == me then
|
||||||
me.send:push({v, true, ...})
|
me.send:push({v, true, ...})
|
||||||
else
|
else
|
||||||
@ -192,9 +191,6 @@ function multi:newProxy(list)
|
|||||||
THREAD = multi.integration.THREAD
|
THREAD = multi.integration.THREAD
|
||||||
end
|
end
|
||||||
local proxy = THREAD.waitFor(self.proxy_link)
|
local proxy = THREAD.waitFor(self.proxy_link)
|
||||||
for i,v in pairs(proxy) do
|
|
||||||
print("proxy",i,v)
|
|
||||||
end
|
|
||||||
proxy.funcs = self.funcs
|
proxy.funcs = self.funcs
|
||||||
return proxy:init()
|
return proxy:init()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||||
-- require("runtests")
|
require("runtests")
|
||||||
-- require("threadtests")
|
require("threadtests")
|
||||||
-- Allows you to run "love tests" which runs the tests
|
-- Allows you to run "love tests" which runs the tests
|
||||||
|
|
||||||
multi, thread = require("multi"):init()
|
multi, thread = require("multi"):init()
|
||||||
|
|||||||
@ -175,7 +175,7 @@ runTest = thread:newFunction(function()
|
|||||||
end
|
end
|
||||||
if not love then
|
if not love then
|
||||||
local ec = 0
|
local ec = 0
|
||||||
if _VERSION == "5.1" then
|
if _VERSION == "Lua 5.1" then
|
||||||
multi.print("Testing pseudo threading")
|
multi.print("Testing pseudo threading")
|
||||||
_, str, ecc = os.execute("lua tests/threadtests.lua p")
|
_, str, ecc = os.execute("lua tests/threadtests.lua p")
|
||||||
ec = ec + ecc
|
ec = ec + ecc
|
||||||
@ -185,14 +185,17 @@ runTest = thread:newFunction(function()
|
|||||||
if ec ~= 0 then
|
if ec ~= 0 then
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
os.exit(0)
|
||||||
else
|
else
|
||||||
multi.print("Testing pseudo threading")
|
multi.print("Testing pseudo threading")
|
||||||
ec = ec + os.execute("lua tests/threadtests.lua p")
|
ec = ec + os.execute("lua tests/threadtests.lua p")
|
||||||
multi.print("Testing lanes threading")
|
multi.print("Testing lanes threading")
|
||||||
ec = ec + os.execute("lua tests/threadtests.lua l")
|
ec = ec + os.execute("lua tests/threadtests.lua l")
|
||||||
|
multi:Stop()
|
||||||
if ec ~= 0 then
|
if ec ~= 0 then
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
os.exit(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||||
multi, thread = require("multi"):init{print=true,warn=true,debugging=true}
|
multi, thread = require("multi"):init{print=true,warn=true,debugging=true}
|
||||||
|
for i,v in pairs(thread) do
|
||||||
|
print(i,v)
|
||||||
|
end
|
||||||
-- require("multi.integration.priorityManager")
|
-- require("multi.integration.priorityManager")
|
||||||
|
|
||||||
-- multi.debugging.OnObjectCreated(function(obj, process)
|
-- multi.debugging.OnObjectCreated(function(obj, process)
|
||||||
@ -267,3 +270,32 @@ multi:mainloop()
|
|||||||
-- end)
|
-- end)
|
||||||
|
|
||||||
-- multi:mainloop()
|
-- multi:mainloop()
|
||||||
|
--[[
|
||||||
|
newFunction function: 0x00fad170
|
||||||
|
waitFor function: 0x00fad0c8
|
||||||
|
request function: 0x00fa4f10
|
||||||
|
newThread function: 0x00fad1b8
|
||||||
|
--__threads table: 0x00fa4dc8
|
||||||
|
defer function: 0x00fa4f98
|
||||||
|
isThread function: 0x00facd40
|
||||||
|
holdFor function: 0x00fa5058
|
||||||
|
yield function: 0x00faccf8
|
||||||
|
hold function: 0x00fa51a0
|
||||||
|
chain function: 0x00fa5180
|
||||||
|
__CORES 32
|
||||||
|
newISOThread function: 0x00fad250
|
||||||
|
newFunctionBase function: 0x00fad128
|
||||||
|
requests table: 0x00fa4e68
|
||||||
|
newProcessor function: 0x00fad190
|
||||||
|
exec function: 0x00fa50e8
|
||||||
|
pushStatus function: 0x00fad108
|
||||||
|
kill function: 0x00faccd8
|
||||||
|
get function: 0x00fad0a8
|
||||||
|
set function: 0x00fad088
|
||||||
|
getCores function: 0x00facd60
|
||||||
|
skip function: 0x00faccb0
|
||||||
|
--_Requests function: 0x00fa50a0
|
||||||
|
getRunningThread function: 0x00fa4fb8
|
||||||
|
holdWithin function: 0x00facc80
|
||||||
|
sleep function: 0x00fa4df0
|
||||||
|
]]
|
||||||
@ -146,7 +146,7 @@ multi:newThread("Scheduler Thread",function()
|
|||||||
local stp = multi:newSystemThreadedProcessor(5)
|
local stp = multi:newSystemThreadedProcessor(5)
|
||||||
|
|
||||||
local tloop = stp:newTLoop(function()
|
local tloop = stp:newTLoop(function()
|
||||||
print("Test")
|
--print("Test")
|
||||||
end, 1)
|
end, 1)
|
||||||
|
|
||||||
multi:newSystemThread("Testing proxy copy THREAD",function(tloop)
|
multi:newSystemThread("Testing proxy copy THREAD",function(tloop)
|
||||||
@ -157,11 +157,11 @@ multi:newThread("Scheduler Thread",function()
|
|||||||
thread:newThread(function()
|
thread:newThread(function()
|
||||||
while true do
|
while true do
|
||||||
thread.hold(tloop.OnLoop)
|
thread.hold(tloop.OnLoop)
|
||||||
print(THREAD_NAME,"Loopy")
|
--print(THREAD_NAME,"Loopy")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
tloop.OnLoop(function(a)
|
tloop.OnLoop(function(a)
|
||||||
print(THREAD_NAME, "Got loop...")
|
--print(THREAD_NAME, "Got loop...")
|
||||||
end)
|
end)
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
end, tloop:getTransferable())
|
end, tloop:getTransferable())
|
||||||
@ -183,12 +183,12 @@ multi:newThread("Scheduler Thread",function()
|
|||||||
thread:newThread(function()
|
thread:newThread(function()
|
||||||
while true do
|
while true do
|
||||||
thread.hold(tloop.OnLoop)
|
thread.hold(tloop.OnLoop)
|
||||||
print(THREAD_NAME,"Local Loopy")
|
--print(THREAD_NAME,"Local Loopy")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
tloop.OnLoop(function()
|
tloop.OnLoop(function()
|
||||||
print("OnLoop",THREAD_NAME)
|
--print("OnLoop",THREAD_NAME)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
t, val = thread.hold(function()
|
t, val = thread.hold(function()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user