Working on 16.0.0 #53

Merged
rayaman merged 120 commits from v16.0.0 into master 2024-02-25 00:00:51 -05:00
5 changed files with 116 additions and 11 deletions
Showing only changes of commit d2cfdfa8e8 - Show all commits

View File

@ -78,18 +78,21 @@ function multi:newSystemThread(name, func, ...)
c.alive = true c.alive = true
c.priority = THREAD.Priority_Normal c.priority = THREAD.Priority_Normal
local multi_settings = multi.defaultSettings local multi_settings = multi.defaultSettings
for i,v in pairs(multi_settings) do local globe = {
print(i,v)
end
c.thread = lanes.gen("*",
{
globals={ -- Set up some globals
THREAD_NAME = name, THREAD_NAME = name,
THREAD_ID = count, THREAD_ID = count,
THREAD = THREAD, THREAD = THREAD,
GLOBAL = GLOBAL, GLOBAL = GLOBAL,
_Console = __ConsoleLinda _Console = __ConsoleLinda
}, }
if GLOBAL["__env"] then
for i,v in pairs(GLOBAL["__env"]) do
globe[i] = v
end
end
c.thread = lanes.gen("*",
{
globals = globe,
priority = c.priority priority = c.priority
},function(...) },function(...)
require("multi"):init(multi_settings) require("multi"):init(multi_settings)
@ -168,7 +171,7 @@ function multi.InitSystemThreadErrorHandler()
end) end)
end end
multi.print("Integrated Lanes!") multi.print("Integrated Lanes Threading!")
multi.integration = {} -- for module creators multi.integration = {} -- for module creators
multi.integration.GLOBAL = GLOBAL multi.integration.GLOBAL = GLOBAL
multi.integration.THREAD = THREAD multi.integration.THREAD = THREAD

View File

@ -134,6 +134,11 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda, __Console)
__GlobalLinda:set(k, v) __GlobalLinda:set(k, v)
end end
}) })
function THREAD.setENV(env)
GLOBAL["__env"] = env
end
return GLOBAL, THREAD return GLOBAL, THREAD
end end

View File

@ -139,6 +139,10 @@ function threads.getGlobal()
) )
end end
function THREAD.setENV(env)
(threads.getGlobal())["__env"] = env
end
function threads.createTable(n) function threads.createTable(n)
local _proxy = {} local _proxy = {}
local function set(name,val) local function set(name,val)

View File

@ -102,6 +102,10 @@ local function INIT(thread)
THREAD.hold = thread.hold THREAD.hold = thread.hold
function THREAD.setENV(env)
GLOBAL["__env"] = env
end
return GLOBAL, THREAD return GLOBAL, THREAD
end end

89
tests/threadtests.lua Normal file
View File

@ -0,0 +1,89 @@
package.path = "../?/init.lua;../?.lua;"..package.path
local multi, thread = require("multi"):init{print=true}--{priority=true}
local proc = multi:newProcessor("Test",true)
local LANES, LOVE, PSEUDO = 1, 2, 3
local env
if love then
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
env = LOVE
else
io.write("Test Pseudo(p), Lanes(l), or love(Run in love environment) Threading: ")
choice = io.read()
if choice == "p" then
GLOBAL, THREAD = require("multi.integration.pseudoManager"):init()
env = PSEUDO
elseif choice == "l" then
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
env = LANES
else
error("Invalid threading choice")
end
end
THREAD.setENV({
multi_assert = function(expected, actual, s)
print("Testing")
if expected ~= actual then
error(s .. " Expected: '".. expected .."' Actual: '".. actual .."'")
end
end
})
multi:newThread("Scheduler Thread",function()
print("Test 1: Thread Spawning, THREAD namaspace in threads, global's working, and queues for passing data.")
queue = multi:newSystemThreadedQueue("Test_Queue"):init()
th1 = multi:newSystemThread("Test_Thread_2", function(a,b,c,d,e,f)
queue = THREAD.waitFor("Test_Queue"):init()
print("!")
multi_assert("Test_Thread_1", THREAD.getName(), "Thread name does not match!")
print("!")
multi_assert("Passing some args", a, "First argument is not as expected 'Passing some args'")
multi_assert(true, e, "Argument e is not true!")
multi_assert("table", type(f), "Argument f is not a table!")
queue:push("done")
end,"Passing some args", 1, 2, 3, true, {"Table"}).OnError(print)
if thread.hold(function()
return queue:pop() == "done"
end,{sleep=1}) == nil then
thread.kill()
end
print("Test 1: Ok")
print("Test 2: Threaded Functions, arg passing, return passing, holding.")
func = THREAD:newFunction(function(a,b,c)
assert(a == 3, "First argument expected '3' got '".. a .."'!")
assert(b == 2, "Second argument expected '2' got '".. a .."'!")
assert(c == 1, "Third argument expected '1' got '".. a .."'!")
return 1, 2, 3, {"a table"}
end, true) -- Hold this
a, b, c, d = func(3,2,1)
print("Returns passed from function", a, b, c, d)
if not a then print(b) end
assert(a == 1, "First return was not '1'!")
assert(b == 2, "Second return was not '2'!")
assert(c == 3, "Third return was not '3'!")
assert(d[1] == "a table", "Fourth return is not table, or doesn't contain 'a table'!")
print("Test 2: Ok")
print("Test 3: SystemThreadedTables")
os.exit()
end).OnError(function(self, err)
print(err)
os.exit()
end)
multi:mainloop()