mirror of
https://github.com/rayaman/multi.git
synced 2026-09-04 23:17:35 -04:00
Working on 16.0.0 (#53)
* Fixed spelling, started ideaing for 16.0.0 * Updated files * Updated readme * Updated version * Concat conns now properly transfer events * Testing types * Connections can be % with functions * Updated connections * Fixed issue with double thread activations (Looking for another solution) * Working on issue with love threaded functions not waiting when in a thread * Working on issue where threads created in threads don't work * Fixed broken threads for love * Fixed some issues with threads * removed test * Updated changes.md * Plan on testing parity between the threading modules * Writing tests for system threading * Added test cases for threading, fixed issues. Todo test love2d * Fixed love2d to succeed with tests * All tests working * Updated files for testing * Modified tests to make it more seamless * removed extra __cores in lanes/pseudo * Working on new priority scheme * Working on priority management * Working on custom prioritySchemes * Fixed issues with missing code * Threaded processors * THREAD.exposeENV(), thread:newProcessor() * Typo in changes.md * Fixed typo in pseudoManager * fixing * Trying to fix exposeENV with pseudoThreading * Changes to threads * updated changes.md * Working on systemthreadedprocess, and experimental newProxy for threading * newProxy and STP work * newProxy implemented * Proxies work with connections now :D * Added tstep to STP, updated changes.md * thread.hold(proxy.conn) * Clean up connection events when holding, working on scheduling tasks/threads to system threaded processors * Getting loads of processors implemented * Finished getLoad(type) * Fixed some bugs * Added an easy way to share a table, found some limitations with lanes threading. * THREAD_NAME set for main thread, connections break the rules for proxies * Testing * Really close to portable proxies, currently extreamly unstable! * Debugging what is going on... * Fixed critical issue with coroutine based threads * Removed extra bloat, proxies are portable now! * Started work on the debugManager * Testing actions, fixing bugs with lanes * Testing... * fixing actions * typo fixed * Throw an error when things break * fixing stuff * Fixed issue with errors not going through * Removed system threaded connections, soon to be replaced by proxies * Testing love2d tests * Test love2d * Use later love-build * Use ubuntu for build * Fixed path * Use appimage * use sudo * No window for love2d * Fixed love2d tests * Testing love2d * Use workspace * Moved other tests while testing * actually pull the repo * packagepath set * Fixed pull * Update multi * Removed link * Edited symlink * Added timeout to build * Rewriting loveManager, too much outdated code * Still implementing new love2d threading code * Rewriting love2d threading binding * Working on adding a Hold method to all objects. Will document how they all work when done. * jobqueues having isues with stp * new pack/unpack for tables, current issue is things being turned into strings * Fixed packing of values into threads, need to fix system proxies and system threaded processors * testing... * Not hard crashing when error is encountered * Should now push non 0 exit codes * Push error when an error happens * Closer to getting things working... * Working on new type system, planning out debugmanager * Fixed error code issue * Test for 5.1 * Planning out debugManager * Some work on the debug manager, proxies working on lanes, todo get pseudo manager and love2d working * Working on getting pseudoThreading tests to work * Added function / connection * Added boost method * Document new features to conns, todo fix newTask * Fixed newTask() * Updated changes.md and fixed some bugs * Added thread.defer(func) * Fixed tests on lanes and pseudo threading, todo fix love2d threading * Fixed paths * Working on paths * Testing paths * Add test for rockspec * Fixed issues * Fixed typo * Added test for defer * Threading working in love2d * Fixed, conf * lanes uses a threaded function like waitfor function * Cleaned up changes.md * added priorityManager to rockspec
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
function love.conf(t)
|
||||
t.identity = nil -- The name of the save directory (string)
|
||||
t.version = "12.0" -- The LOVE version this game was made for (string)
|
||||
t.console = true -- Attach a console (boolean, Windows only)
|
||||
|
||||
t.window.title = "MultiThreadTest" -- The window title (string)
|
||||
t.window.icon = nil -- Filepath to an image to use as the window's icon (string)
|
||||
t.window.width = 1280 -- The window width (number)
|
||||
t.window.height = 720 -- The window height (number)
|
||||
|
||||
t.window.borderless = false -- Remove all border visuals from the window (boolean)
|
||||
t.window.resizable = true -- Let the window be user-resizable (boolean)
|
||||
t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
|
||||
t.window.minheight = 1 -- Minimum window height if the window is resizable (number)
|
||||
t.window.fullscreen = false -- Enable fullscreen (boolean)
|
||||
t.window.fullscreentype = "desktop" -- Standard fullscreen or desktop fullscreen mode (string)
|
||||
t.window.vsync = false -- Enable vertical sync (boolean)
|
||||
t.window.fsaa = 2 -- The number of samples to use with multi-sampled antialiasing (number)
|
||||
t.window.display = 1 -- Index of the monitor to show the window in (number)
|
||||
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
|
||||
t.window.srgb = false -- Enable sRGB gamma correction when drawing to the screen (boolean)
|
||||
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
|
||||
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
|
||||
|
||||
t.modules.audio = false -- Enable the audio module (boolean)
|
||||
t.modules.event = false -- Enable the event module (boolean)
|
||||
t.modules.graphics = false -- Enable the graphics module (boolean)
|
||||
t.modules.image = false -- Enable the image module (boolean)
|
||||
t.modules.joystick = false -- Enable the joystick module (boolean)
|
||||
t.modules.keyboard = false -- Enable the keyboard module (boolean)
|
||||
t.modules.math = false -- Enable the math module (boolean)
|
||||
t.modules.mouse = false -- Enable the mouse module (boolean)
|
||||
t.modules.physics = false -- Enable the physics module (boolean)
|
||||
t.modules.sound = false -- Enable the sound module (boolean)
|
||||
t.modules.system = false -- Enable the system module (boolean)
|
||||
t.modules.timer = false -- Enable the timer module (boolean)
|
||||
t.modules.window = false -- Enable the window module (boolean)
|
||||
t.modules.thread = true -- Enable the thread module (boolean)
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
|
||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
require("lldebugger").start()
|
||||
end
|
||||
|
||||
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||
|
||||
require("runtests")
|
||||
require("threadtests")
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../
|
||||
+192
-184
@@ -1,185 +1,193 @@
|
||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
package.path="multi/?.lua;multi/?/init.lua;multi/?.lua;multi/?/?/init.lua;"..package.path
|
||||
require("lldebugger").start()
|
||||
else
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
end
|
||||
--[[
|
||||
This file runs all tests.
|
||||
Format:
|
||||
Expected:
|
||||
...
|
||||
...
|
||||
...
|
||||
Actual:
|
||||
...
|
||||
...
|
||||
...
|
||||
|
||||
Each test that is ran should have a 5 second pause after the test is complete
|
||||
The expected and actual should "match" (Might be impossible when playing with threads)
|
||||
This will be pushed directly to the master as tests start existing.
|
||||
]]
|
||||
local multi, thread = require("multi"):init{print=true}--{priority=true}
|
||||
local good = false
|
||||
local proc = multi:newProcessor("Test",true)
|
||||
proc:newAlarm(3):OnRing(function()
|
||||
good = true
|
||||
end)
|
||||
|
||||
runTest = thread:newFunction(function()
|
||||
local alarms,tsteps,steps,loops,tloops,updaters,events=false,0,0,0,0,0,false
|
||||
print("Testing Basic Features. If this fails most other features will probably not work!")
|
||||
proc:newAlarm(2):OnRing(function(a)
|
||||
alarms = true
|
||||
a:Destroy()
|
||||
end)
|
||||
proc:newTStep(1,10,1,.1):OnStep(function(t)
|
||||
tsteps = tsteps + 1
|
||||
end):OnEnd(function(step)
|
||||
step:Destroy()
|
||||
end)
|
||||
proc:newStep(1,10):OnStep(function(s)
|
||||
steps = steps + 1
|
||||
end):OnEnd(function(step)
|
||||
step:Destroy()
|
||||
end)
|
||||
local loop = proc:newLoop(function(l)
|
||||
loops = loops + 1
|
||||
end)
|
||||
proc:newTLoop(function(t)
|
||||
tloops = tloops + 1
|
||||
end,.1)
|
||||
local updater = proc:newUpdater(1):OnUpdate(function()
|
||||
updaters = updaters + 1
|
||||
end)
|
||||
local event = proc:newEvent(function()
|
||||
return alarms
|
||||
end)
|
||||
event.OnEvent(function(evnt)
|
||||
evnt:Destroy()
|
||||
events = true
|
||||
print("Alarms: Ok")
|
||||
print("Events: Ok")
|
||||
if tsteps == 10 then print("TSteps: Ok") else print("TSteps: Bad!") end
|
||||
if steps == 10 then print("Steps: Ok") else print("Steps: Bad!") end
|
||||
if loops > 100 then print("Loops: Ok") else print("Loops: Bad!") end
|
||||
if tloops > 10 then print("TLoops: Ok") else print("TLoops: Bad!") end
|
||||
if updaters > 100 then print("Updaters: Ok") else print("Updaters: Bad!") end
|
||||
end)
|
||||
thread.hold(event.OnEvent)
|
||||
print("Starting Connection and Thread tests!")
|
||||
func = thread:newFunction(function(count)
|
||||
print("Starting Status test: ",count)
|
||||
local a = 0
|
||||
while true do
|
||||
a = a + 1
|
||||
thread.sleep(.1)
|
||||
thread.pushStatus(a,count)
|
||||
if a == count then break end
|
||||
end
|
||||
return "Done", true, math.random(1,10000)
|
||||
end)
|
||||
local ret = func(10)
|
||||
local ret2 = func(15)
|
||||
local ret3 = func(20)
|
||||
local s1,s2,s3 = 0,0,0
|
||||
ret.OnError(function(...)
|
||||
print("Func 1:",...)
|
||||
end)
|
||||
ret2.OnError(function(...)
|
||||
print("Func 2:",...)
|
||||
end)
|
||||
ret3.OnError(function(...)
|
||||
print("Func 3:",...)
|
||||
end)
|
||||
ret.OnStatus(function(part,whole)
|
||||
s1 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
ret2.OnStatus(function(part,whole)
|
||||
s2 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
ret3.OnStatus(function(part,whole)
|
||||
s3 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
|
||||
ret.OnReturn(function(...)
|
||||
print("Done 1",...)
|
||||
end)
|
||||
ret2.OnReturn(function(...)
|
||||
print("Done 2",...)
|
||||
end)
|
||||
ret3.OnReturn(function(...)
|
||||
print("Done 3",...)
|
||||
end)
|
||||
|
||||
local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)
|
||||
|
||||
if s1 == 100 and s2 == 100 and s3 == 100 then
|
||||
print("Threads: All tests Ok")
|
||||
else
|
||||
if s1>0 and s2>0 and s3 > 0 then
|
||||
print("Thread OnStatus: Ok")
|
||||
else
|
||||
print("Threads OnStatus or thread.hold(conn) Error!")
|
||||
end
|
||||
if timeout then
|
||||
print("Connection Error!")
|
||||
else
|
||||
print("Connection Test 1: Ok")
|
||||
end
|
||||
print("Connection holding Error!")
|
||||
end
|
||||
|
||||
conn1 = proc:newConnection()
|
||||
conn2 = proc:newConnection()
|
||||
conn3 = proc:newConnection()
|
||||
local c1,c2,c3,c4 = false,false,false,false
|
||||
|
||||
local a = conn1(function()
|
||||
c1 = true
|
||||
end)
|
||||
|
||||
local b = conn2(function()
|
||||
c2 = true
|
||||
end)
|
||||
|
||||
local c = conn3(function()
|
||||
c3 = true
|
||||
end)
|
||||
|
||||
local d = conn3(function()
|
||||
c4 = true
|
||||
end)
|
||||
|
||||
conn1:Fire()
|
||||
conn2:Fire()
|
||||
conn3:Fire()
|
||||
|
||||
if c1 and c2 and c3 and c4 then
|
||||
print("Connection Test 2: Ok")
|
||||
else
|
||||
print("Connection Test 2: Error")
|
||||
end
|
||||
c3 = false
|
||||
c4 = false
|
||||
d:Destroy()
|
||||
conn3:Fire()
|
||||
if c3 and not(c4) then
|
||||
print("Connection Test 3: Ok")
|
||||
else
|
||||
print("Connection Test 3: Error removing connection")
|
||||
end
|
||||
os.exit() -- End of tests
|
||||
end)
|
||||
|
||||
print(runTest().OnError(function(...)
|
||||
print("Error: Something went wrong with the test!")
|
||||
print(...)
|
||||
os.exit(1)
|
||||
end))
|
||||
|
||||
print("Pumping proc")
|
||||
while true do
|
||||
proc.run()
|
||||
package.path = "../?/init.lua;../?.lua;./init.lua;./?.lua;"..package.path
|
||||
|
||||
local multi, thread = require("multi"):init{print=true,warn=true,error=true}--{priority=true}
|
||||
local good = false
|
||||
local proc = multi:newProcessor("Test")
|
||||
|
||||
proc.Start()
|
||||
|
||||
proc:newAlarm(3):OnRing(function()
|
||||
good = true
|
||||
end)
|
||||
|
||||
runTest = thread:newFunction(function()
|
||||
local alarms,tsteps,steps,loops,tloops,updaters,events=false,0,0,0,0,0,false
|
||||
multi.print("Testing Basic Features. If this fails most other features will probably not work!")
|
||||
proc:newAlarm(2):OnRing(function(a)
|
||||
alarms = true
|
||||
a:Destroy()
|
||||
end)
|
||||
proc:newTStep(1,10,1,.1):OnStep(function(t)
|
||||
tsteps = tsteps + 1
|
||||
end):OnEnd(function(step)
|
||||
step:Destroy()
|
||||
end)
|
||||
proc:newStep(1,10):OnStep(function(s)
|
||||
steps = steps + 1
|
||||
end):OnEnd(function(step)
|
||||
step:Destroy()
|
||||
end)
|
||||
local loop = proc:newLoop(function(l)
|
||||
loops = loops + 1
|
||||
end)
|
||||
proc:newTLoop(function(t)
|
||||
tloops = tloops + 1
|
||||
end,.1)
|
||||
local updater = proc:newUpdater(1):OnUpdate(function()
|
||||
updaters = updaters + 1
|
||||
end)
|
||||
local event = proc:newEvent(function()
|
||||
return alarms
|
||||
end)
|
||||
event.OnEvent(function(evnt)
|
||||
evnt:Destroy()
|
||||
events = true
|
||||
multi.success("Alarms: Ok")
|
||||
multi.success("Events: Ok")
|
||||
if tsteps == 10 then multi.success("TSteps: Ok") else multi.error("TSteps: Bad!") end
|
||||
if steps == 10 then multi.success("Steps: Ok") else multi.error("Steps: Bad!") end
|
||||
if loops > 100 then multi.success("Loops: Ok") else multi.error("Loops: Bad!") end
|
||||
if tloops > 10 then multi.success("TLoops: Ok") else multi.error("TLoops: Bad!") end
|
||||
if updaters > 100 then multi.success("Updaters: Ok") else multi.error("Updaters: Bad!") end
|
||||
end)
|
||||
thread.hold(event.OnEvent)
|
||||
multi.print("Starting Connection and Thread tests!")
|
||||
func = thread:newFunction(function(count)
|
||||
multi.print("Starting Status test: ",count)
|
||||
local a = 0
|
||||
while true do
|
||||
a = a + 1
|
||||
thread.sleep(.1)
|
||||
thread.pushStatus(a,count)
|
||||
if a == count then break end
|
||||
end
|
||||
return "Done", true, math.random(1,10000)
|
||||
end)
|
||||
local ret = func(10)
|
||||
local ret2 = func(15)
|
||||
local ret3 = func(20)
|
||||
local s1,s2,s3 = 0,0,0
|
||||
ret.OnError(function(...)
|
||||
multi.error("Func 1:",...)
|
||||
end)
|
||||
ret2.OnError(function(...)
|
||||
multi.error("Func 2:",...)
|
||||
end)
|
||||
ret3.OnError(function(...)
|
||||
multi.error("Func 3:",...)
|
||||
end)
|
||||
ret.OnStatus(function(part,whole)
|
||||
s1 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
ret2.OnStatus(function(part,whole)
|
||||
s2 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
ret3.OnStatus(function(part,whole)
|
||||
s3 = math.ceil((part/whole)*1000)/10
|
||||
end)
|
||||
|
||||
ret.OnReturn(function(...)
|
||||
multi.success("Done 1",...)
|
||||
end)
|
||||
ret2.OnReturn(function(...)
|
||||
multi.success("Done 2",...)
|
||||
end)
|
||||
ret3.OnReturn(function(...)
|
||||
multi.success("Done 3",...)
|
||||
end)
|
||||
|
||||
local err, timeout = thread.hold(ret.OnReturn * ret2.OnReturn * ret3.OnReturn)
|
||||
|
||||
if s1 == 100 and s2 == 100 and s3 == 100 then
|
||||
multi.success("Threads: All tests Ok")
|
||||
else
|
||||
if s1>0 and s2>0 and s3 > 0 then
|
||||
multi.success("Thread OnStatus: Ok")
|
||||
else
|
||||
multi.error("Threads OnStatus or thread.hold(conn) Error!")
|
||||
end
|
||||
if timeout then
|
||||
multi.error("Connection Error!")
|
||||
else
|
||||
multi.success("Connection Test 1: Ok")
|
||||
end
|
||||
multi.error("Connection holding Error!")
|
||||
end
|
||||
|
||||
conn1 = proc:newConnection()
|
||||
conn2 = proc:newConnection()
|
||||
conn3 = proc:newConnection()
|
||||
local c1,c2,c3,c4 = false,false,false,false
|
||||
|
||||
local a = conn1(function()
|
||||
c1 = true
|
||||
end)
|
||||
|
||||
local b = conn2(function()
|
||||
c2 = true
|
||||
end)
|
||||
|
||||
local c = conn3(function()
|
||||
c3 = true
|
||||
end)
|
||||
|
||||
local d = conn3(function()
|
||||
c4 = true
|
||||
end)
|
||||
|
||||
conn1:Fire()
|
||||
conn2:Fire()
|
||||
conn3:Fire()
|
||||
|
||||
if c1 and c2 and c3 and c4 then
|
||||
multi.success("Connection Test 2: Ok")
|
||||
else
|
||||
multi.error("Connection Test 2: Error")
|
||||
end
|
||||
c3 = false
|
||||
c4 = false
|
||||
conn3:Unconnect(d)
|
||||
conn3:Fire()
|
||||
if c3 and not(c4) then
|
||||
multi.success("Connection Test 3: Ok")
|
||||
else
|
||||
multi.error("Connection Test 3: Error removing connection")
|
||||
end
|
||||
if not love then
|
||||
local ec = 0
|
||||
multi.print("Testing pseudo threading")
|
||||
capture = io.popen("lua tests/threadtests.lua p"):read("*a")
|
||||
if capture:lower():match("error") then
|
||||
ec = ec + 1
|
||||
os.exit(1)
|
||||
else
|
||||
io.write(capture)
|
||||
end
|
||||
multi.print("Testing lanes threading")
|
||||
capture = io.popen("lua tests/threadtests.lua l"):read("*a")
|
||||
if capture:lower():match("error") then
|
||||
ec = ec + 1
|
||||
os.exit(1)
|
||||
else
|
||||
io.write(capture)
|
||||
end
|
||||
os.exit(0)
|
||||
end
|
||||
end)
|
||||
|
||||
local handle = runTest()
|
||||
|
||||
handle.OnError(function(...)
|
||||
multi.error("Something went wrong with the test!")
|
||||
print(...)
|
||||
end)
|
||||
|
||||
if not love then
|
||||
multi:mainloop()
|
||||
else
|
||||
local hold = thread:newFunction(function()
|
||||
thread.hold(handle.OnError + handle.OnReturn)
|
||||
end, true)
|
||||
hold()
|
||||
multi.print("Starting Threading tests!")
|
||||
end
|
||||
+298
-133
@@ -1,133 +1,298 @@
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
multi, thread = require("multi"):init{print=true,findopt=true}
|
||||
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
||||
multi:getOptimizationConnection()(function(msg)
|
||||
print(msg)
|
||||
end)
|
||||
|
||||
-- local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection():fastMode(), multi:newConnection()
|
||||
|
||||
-- local link = conn1(function()
|
||||
-- print("Conn1, first")
|
||||
-- end)
|
||||
|
||||
-- local link2 = conn1(function()
|
||||
-- print("Conn1, second")
|
||||
-- end)
|
||||
|
||||
-- local link3 = conn1(function()
|
||||
-- print("Conn1, third")
|
||||
-- end)
|
||||
|
||||
-- local link4 = conn2(function()
|
||||
-- print("Conn2, first")
|
||||
-- end)
|
||||
|
||||
-- local link5 = conn2(function()
|
||||
-- print("Conn2, second")
|
||||
-- end)
|
||||
|
||||
-- local link6 = conn2(function()
|
||||
-- print("Conn2, third")
|
||||
-- end)
|
||||
|
||||
-- print("All conns\n-------------")
|
||||
-- conn1:Fire()
|
||||
-- conn2:Fire()
|
||||
|
||||
-- conn1:Unconnect(link3)
|
||||
-- conn2:Unconnect(link6)
|
||||
-- print("All conns Edit\n---------------------")
|
||||
-- conn1:Fire()
|
||||
-- conn2:Fire()
|
||||
|
||||
-- thread:newThread(function()
|
||||
-- print("Awaiting status")
|
||||
-- thread.hold(conn1 + (conn2 * conn3))
|
||||
-- print("Conn or Conn2 and Conn3")
|
||||
-- end)
|
||||
|
||||
-- multi:newAlarm(1):OnRing(function()
|
||||
-- print("Conn")
|
||||
-- conn1:Fire()
|
||||
-- end)
|
||||
-- multi:newAlarm(2):OnRing(function()
|
||||
-- print("Conn2")
|
||||
-- conn2:Fire()
|
||||
-- end)
|
||||
-- multi:newAlarm(3):OnRing(function()
|
||||
-- print("Conn3")
|
||||
-- conn3:Fire()
|
||||
-- end)
|
||||
|
||||
local conn = multi:newSystemThreadedConnection("conn"):init()
|
||||
|
||||
multi:newSystemThread("Thread_Test_1", function()
|
||||
local multi, thread = require("multi"):init()
|
||||
local conn = GLOBAL["conn"]:init()
|
||||
local console = THREAD.getConsole()
|
||||
conn(function(a,b,c)
|
||||
console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||
end)
|
||||
multi:mainloop()
|
||||
end)
|
||||
|
||||
multi:newSystemThread("Thread_Test_2", function()
|
||||
local multi, thread = require("multi"):init()
|
||||
local conn = GLOBAL["conn"]:init()
|
||||
local console = THREAD.getConsole()
|
||||
conn(function(a,b,c)
|
||||
console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||
end)
|
||||
multi:newAlarm(2):OnRing(function()
|
||||
console.print("Fire 2!!!")
|
||||
conn:Fire(4,5,6)
|
||||
THREAD.kill()
|
||||
end)
|
||||
|
||||
multi:mainloop()
|
||||
end)
|
||||
local console = THREAD.getConsole()
|
||||
conn(function(a,b,c)
|
||||
console.print("Mainloop conn got triggered!",a,b,c)
|
||||
end)
|
||||
|
||||
alarm = multi:newAlarm(1)
|
||||
alarm:OnRing(function()
|
||||
console.print("Fire 1!!!")
|
||||
conn:Fire(1,2,3)
|
||||
end)
|
||||
|
||||
alarm = multi:newAlarm(3):OnRing(function()
|
||||
multi:newSystemThread("Thread_Test_3",function()
|
||||
local multi, thread = require("multi"):init()
|
||||
local conn = GLOBAL["conn"]:init()
|
||||
local console = THREAD.getConsole()
|
||||
conn(function(a,b,c)
|
||||
console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||
end)
|
||||
multi:newAlarm(4):OnRing(function()
|
||||
console.print("Fire 3!!!")
|
||||
conn:Fire(7,8,9)
|
||||
end)
|
||||
multi:mainloop()
|
||||
end)
|
||||
end)
|
||||
|
||||
multi:newSystemThread("Thread_Test_4",function()
|
||||
local multi, thread = require("multi"):init()
|
||||
local conn = GLOBAL["conn"]:init()
|
||||
local conn2 = multi:newConnection()
|
||||
local console = THREAD.getConsole()
|
||||
multi:newAlarm(2):OnRing(function()
|
||||
conn2:Fire()
|
||||
end)
|
||||
multi:newThread(function()
|
||||
console.print("Conn Test!")
|
||||
thread.hold(conn + conn2)
|
||||
console.print("It held!")
|
||||
end)
|
||||
multi:mainloop()
|
||||
end)
|
||||
|
||||
multi:mainloop()
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
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")
|
||||
|
||||
-- multi.debugging.OnObjectCreated(function(obj, process)
|
||||
-- multi.print("Created:", obj.Type, "in", process.Type, process:getFullName())
|
||||
-- end)
|
||||
|
||||
-- multi.debugging.OnObjectDestroyed(function(obj, process)
|
||||
-- multi.print("Destroyed:", obj.Type, "in", process.Type, process:getFullName())
|
||||
-- end)
|
||||
|
||||
|
||||
-- test = multi:newProcessor("Test")
|
||||
-- test:setPriorityScheme(multi.priorityScheme.TimeBased)
|
||||
|
||||
-- test:newUpdater(10000000):OnUpdate(function()
|
||||
-- print("Print is slowish")
|
||||
-- end)
|
||||
|
||||
-- print("Running...")
|
||||
|
||||
-- local conn1, conn2 = multi:newConnection(), multi:newConnection()
|
||||
-- conn3 = conn1 + conn2
|
||||
|
||||
-- conn1(function()
|
||||
-- print("Hi 1")
|
||||
-- end)
|
||||
|
||||
-- conn2(function()
|
||||
-- print("Hi 2")
|
||||
-- end)
|
||||
|
||||
-- conn3(function()
|
||||
-- print("Hi 3")
|
||||
-- end)
|
||||
|
||||
-- function test(a,b,c)
|
||||
-- print("I run before all and control if execution should continue!")
|
||||
-- return a>b
|
||||
-- end
|
||||
|
||||
-- conn4 = test .. conn1
|
||||
|
||||
-- conn5 = conn2 .. function() print("I run after it all!") end
|
||||
|
||||
-- conn4:Fire(3,2,3)
|
||||
-- -- This second one won't trigger the Hi's
|
||||
-- conn4:Fire(1,2,3)
|
||||
|
||||
-- conn5(function()
|
||||
-- print("Test 1")
|
||||
-- end)
|
||||
|
||||
-- conn5(function()
|
||||
-- print("Test 2")
|
||||
-- end)
|
||||
|
||||
-- conn5(function()
|
||||
-- print("Test 3")
|
||||
-- end)
|
||||
|
||||
-- conn5:Fire()
|
||||
|
||||
|
||||
|
||||
|
||||
-- multi.print("Testing thread:newProcessor()")
|
||||
|
||||
-- proc = thread:newProcessor("Test")
|
||||
|
||||
-- proc:newLoop(function()
|
||||
-- multi.print("Running...")
|
||||
-- thread.sleep(1)
|
||||
-- end)
|
||||
|
||||
-- proc:newThread(function()
|
||||
-- while true do
|
||||
-- multi.warn("Everything is a thread in this proc!")
|
||||
-- thread.sleep(1)
|
||||
-- end
|
||||
-- end)
|
||||
|
||||
-- proc:newAlarm(5):OnRing(function(a)
|
||||
-- multi.print(";) Goodbye")
|
||||
-- a:Destroy()
|
||||
-- end)
|
||||
|
||||
-- local func = thread:newFunction(function()
|
||||
-- thread.sleep(4)
|
||||
-- print("Hello!")
|
||||
-- end)
|
||||
|
||||
-- multi:newTLoop(func, 1)
|
||||
|
||||
-- multi:mainloop()
|
||||
|
||||
-- multi:setTaskDelay(.05)
|
||||
-- multi:newTask(function()
|
||||
-- for i = 1, 10 do
|
||||
-- multi:newTask(function()
|
||||
-- print("Task "..i)
|
||||
-- end)
|
||||
-- end
|
||||
-- end)
|
||||
|
||||
-- local conn = multi:newConnection()
|
||||
-- conn(function() print("Test 1") end)
|
||||
-- conn(function() print("Test 2") end)
|
||||
-- conn(function() print("Test 3") end)
|
||||
-- conn(function() print("Test 4") end)
|
||||
|
||||
-- print("Fire 1")
|
||||
-- conn:Fire()
|
||||
-- conn = -conn
|
||||
-- print("Fire 2")
|
||||
-- conn:Fire()
|
||||
|
||||
-- print(#conn)
|
||||
|
||||
-- thread:newThread("Test thread", function()
|
||||
-- print("Starting thread!")
|
||||
-- thread.defer(function() -- Runs when the thread finishes execution
|
||||
-- print("Clean up time!")
|
||||
-- end)
|
||||
-- --[[
|
||||
-- Do lot's of stuff
|
||||
-- ]]
|
||||
-- thread.sleep(3)
|
||||
-- end)
|
||||
|
||||
multi:mainloop()
|
||||
|
||||
-- local conn1, conn2, conn3 = multi:newConnection(nil,nil,true), multi:newConnection(), multi:newConnection()
|
||||
|
||||
-- local link = conn1(function()
|
||||
-- print("Conn1, first")
|
||||
-- end)
|
||||
|
||||
-- local link2 = conn1(function()
|
||||
-- print("Conn1, second")
|
||||
-- end)
|
||||
|
||||
-- local link3 = conn1(function()
|
||||
-- print("Conn1, third")
|
||||
-- end)
|
||||
|
||||
-- local link4 = conn2(function()
|
||||
-- print("Conn2, first")
|
||||
-- end)
|
||||
|
||||
-- local link5 = conn2(function()
|
||||
-- print("Conn2, second")
|
||||
-- end)
|
||||
|
||||
-- local link6 = conn2(function()
|
||||
-- print("Conn2, third")
|
||||
-- end)
|
||||
|
||||
-- print("Links 1-6",link,link2,link3,link4,link5,link6)
|
||||
-- conn1:Lock(link)
|
||||
-- print("All conns\n-------------")
|
||||
-- conn1:Fire()
|
||||
-- conn2:Fire()
|
||||
|
||||
-- conn1:Unlock(link)
|
||||
|
||||
-- conn1:Unconnect(link3)
|
||||
-- conn2:Unconnect(link6)
|
||||
-- print("All conns Edit\n---------------------")
|
||||
-- conn1:Fire()
|
||||
-- conn2:Fire()
|
||||
|
||||
-- thread:newThread(function()
|
||||
-- print("Awaiting status")
|
||||
-- thread.hold(conn1 + (conn2 * conn3))
|
||||
-- print("Conn or Conn2 and Conn3")
|
||||
-- end)
|
||||
|
||||
-- multi:newAlarm(1):OnRing(function()
|
||||
-- print("Conn")
|
||||
-- conn1:Fire()
|
||||
-- end)
|
||||
-- multi:newAlarm(2):OnRing(function()
|
||||
-- print("Conn2")
|
||||
-- conn2:Fire()
|
||||
-- end)
|
||||
-- multi:newAlarm(3):OnRing(function()
|
||||
-- print("Conn3")
|
||||
-- conn3:Fire()
|
||||
-- os.exit()
|
||||
-- end)
|
||||
|
||||
|
||||
-- local conn = multi:newSystemThreadedConnection("conn"):init()
|
||||
|
||||
-- multi:newSystemThread("Thread_Test_1", function()
|
||||
-- local multi, thread = require("multi"):init()
|
||||
-- local conn = GLOBAL["conn"]:init()
|
||||
-- local console = THREAD.getConsole()
|
||||
-- conn(function(a,b,c)
|
||||
-- console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||
-- end)
|
||||
-- multi:mainloop()
|
||||
-- end)
|
||||
|
||||
-- multi:newSystemThread("Thread_Test_2", function()
|
||||
-- local multi, thread = require("multi"):init()
|
||||
-- local conn = GLOBAL["conn"]:init()
|
||||
-- local console = THREAD.getConsole()
|
||||
-- conn(function(a,b,c)
|
||||
-- console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||
-- end)
|
||||
-- multi:newAlarm(2):OnRing(function()
|
||||
-- console.print("Fire 2!!!")
|
||||
-- conn:Fire(4,5,6)
|
||||
-- THREAD.kill()
|
||||
-- end)
|
||||
|
||||
-- multi:mainloop()
|
||||
-- end)
|
||||
-- local console = THREAD.getConsole()
|
||||
-- conn(function(a,b,c)
|
||||
-- console.print("Mainloop conn got triggered!",a,b,c)
|
||||
-- end)
|
||||
|
||||
-- alarm = multi:newAlarm(1)
|
||||
-- alarm:OnRing(function()
|
||||
-- console.print("Fire 1!!!")
|
||||
-- conn:Fire(1,2,3)
|
||||
-- end)
|
||||
|
||||
-- alarm = multi:newAlarm(3):OnRing(function()
|
||||
-- multi:newSystemThread("Thread_Test_3",function()
|
||||
-- local multi, thread = require("multi"):init()
|
||||
-- local conn = GLOBAL["conn"]:init()
|
||||
-- local console = THREAD.getConsole()
|
||||
-- conn(function(a,b,c)
|
||||
-- console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||
-- end)
|
||||
-- multi:newAlarm(4):OnRing(function()
|
||||
-- console.print("Fire 3!!!")
|
||||
-- conn:Fire(7,8,9)
|
||||
-- end)
|
||||
-- multi:mainloop()
|
||||
-- end)
|
||||
-- end)
|
||||
|
||||
-- multi:newSystemThread("Thread_Test_4",function()
|
||||
-- local multi, thread = require("multi"):init()
|
||||
-- local conn = GLOBAL["conn"]:init()
|
||||
-- local conn2 = multi:newConnection()
|
||||
-- local console = THREAD.getConsole()
|
||||
-- multi:newAlarm(2):OnRing(function()
|
||||
-- conn2:Fire()
|
||||
-- end)
|
||||
-- multi:newThread(function()
|
||||
-- console.print("Conn Test!")
|
||||
-- thread.hold(conn + conn2)
|
||||
-- console.print("It held!")
|
||||
-- end)
|
||||
-- multi:mainloop()
|
||||
-- end)
|
||||
|
||||
-- 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
|
||||
]]
|
||||
@@ -0,0 +1,246 @@
|
||||
package.path = "D:/VSCWorkspace/?/init.lua;D:/VSCWorkspace/?.lua;"..package.path
|
||||
package.cpath = "C:/luaInstalls/lua5.4/lib/lua/5.4/?/core.dll;" .. package.cpath
|
||||
multi, thread = require("multi"):init{error=true,warning=true,print=true, priority=true}
|
||||
proc = multi:newProcessor("Thread Test",true)
|
||||
local LANES, LOVE, PSEUDO = 1, 2, 3
|
||||
local env, we_good
|
||||
|
||||
if love then
|
||||
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||
env = LOVE
|
||||
elseif arg[1] == "l" then
|
||||
GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
|
||||
env = LANES
|
||||
elseif arg[1] == "p" then
|
||||
GLOBAL, THREAD = require("multi.integration.pseudoManager"):init()
|
||||
env = PSEUDO
|
||||
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
|
||||
|
||||
multi.print("Testing THREAD.setENV() if the multi_assert is not found then there is a problem")
|
||||
THREAD.setENV({
|
||||
multi_assert = function(expected, actual, s)
|
||||
if expected ~= actual then
|
||||
multi.error(s .. " Expected: '".. tostring(expected) .."' Actual: '".. tostring(actual) .."'")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
multi:newThread("Scheduler Thread",function()
|
||||
multi:newThread(function()
|
||||
thread.sleep(30)
|
||||
print("Timeout tests took longer than 30 seconds")
|
||||
multi:Stop()
|
||||
os.exit(1)
|
||||
end)
|
||||
|
||||
queue = multi:newSystemThreadedQueue("Test_Queue")
|
||||
defer_queue = multi:newSystemThreadedQueue("Defer_Queue")
|
||||
|
||||
multi:newSystemThread("Test_Thread_0", function()
|
||||
defer_queue = THREAD.waitFor("Defer_Queue"):init()
|
||||
|
||||
THREAD.defer(function()
|
||||
defer_queue:push("done")
|
||||
multi.print("This function was defered until the end of the threads life")
|
||||
end)
|
||||
|
||||
multi.print("Testing defer, should print below this")
|
||||
|
||||
if THREAD_NAME~="Test_Thread_0" then
|
||||
multi.error("The name should be Test_Thread_0",THREAD_NAME,THREAD_NAME,_G.THREAD_NAME)
|
||||
end
|
||||
end)
|
||||
|
||||
if thread.hold(function()
|
||||
return defer_queue:pop() == "done"
|
||||
end,{sleep=3}) == nil then
|
||||
multi.error("Thread.defer didn't work!")
|
||||
end
|
||||
|
||||
th1 = multi:newSystemThread("Test_Thread_1", function(a,b,c,d,e,f)
|
||||
queue = THREAD.waitFor("Test_Queue"):init()
|
||||
multi_assert("Test_Thread_1", THREAD_NAME, "Thread name does not match!")
|
||||
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(function(self,err)
|
||||
multi.error(err)
|
||||
os.exit(1)
|
||||
end)
|
||||
|
||||
if thread.hold(function()
|
||||
return queue:pop() == "done"
|
||||
end,{sleep=1}) == nil then
|
||||
thread.kill()
|
||||
end
|
||||
|
||||
multi.success("Thread Spawning, THREAD namaspace in threads, global's working, and queues for passing data: Ok")
|
||||
|
||||
func = THREAD:newFunction(function(a,b,c)
|
||||
assert(a == 3, "First argument expected '3' got '".. a .."'!")
|
||||
assert(b == 2, "Second argument expected '2' got '".. b .."'!")
|
||||
assert(c == 1, "Third argument expected '1' got '".. c .."'!")
|
||||
return 1, 2, 3, {"a table"}
|
||||
end, true) -- Hold this
|
||||
|
||||
a, b, c, d = func(3,2,1)
|
||||
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'!")
|
||||
|
||||
multi.success("Threaded Functions, arg passing, return passing, holding: Ok")
|
||||
|
||||
test=multi:newSystemThreadedTable("YO"):init()
|
||||
test["test1"]="tabletest"
|
||||
local worked = false
|
||||
|
||||
multi:newSystemThread("testing tables",function()
|
||||
tab=THREAD.waitFor("YO")
|
||||
THREAD.hold(function() return tab["test1"] end)
|
||||
THREAD.sleep(.1)
|
||||
tab["test2"] = "Whats so funny?"
|
||||
end).OnError(multi.error)
|
||||
|
||||
multi:newThread("test2",function()
|
||||
thread.hold(function() return test["test2"] end)
|
||||
worked = true
|
||||
end)
|
||||
|
||||
t, val = thread.hold(function()
|
||||
return worked
|
||||
end,{sleep=2})
|
||||
|
||||
if val == multi.TIMEOUT then
|
||||
multi.error("SystemThreadedTables: Failed")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
multi.success("SystemThreadedTables: Ok")
|
||||
|
||||
local ready = false
|
||||
|
||||
jq = multi:newSystemThreadedJobQueue(4) -- Job queue with 4 worker threads
|
||||
func2 = jq:newFunction("sleep",function(a,b)
|
||||
THREAD.sleep(.2)
|
||||
end)
|
||||
func = jq:newFunction("test-thread",function(a,b)
|
||||
sleep()
|
||||
return a+b
|
||||
end)
|
||||
local count = 0
|
||||
for i = 1,10 do
|
||||
func(i, i*3).OnReturn(function(data)
|
||||
count = count + 1
|
||||
end)
|
||||
end
|
||||
|
||||
t, val = thread.hold(function()
|
||||
return count == 10
|
||||
end,{sleep=3})
|
||||
|
||||
if val == multi.TIMEOUT then
|
||||
multi.error("SystemThreadedJobQueues: Failed")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
multi.success("SystemThreadedJobQueues: Ok")
|
||||
|
||||
local proxy_test = false
|
||||
local stp = multi:newSystemThreadedProcessor(5)
|
||||
|
||||
local tloop = stp:newTLoop(function()
|
||||
--print("Test")
|
||||
end, 1)
|
||||
|
||||
multi:newSystemThread("PROX_THREAD",function(tloop)
|
||||
local multi, thread = require("multi"):init()
|
||||
tloop = tloop:init()
|
||||
multi.print("tloop type:",tloop.Type)
|
||||
multi.print("Testing proxies on other threads")
|
||||
thread:newThread(function()
|
||||
while true do
|
||||
thread.hold(tloop.OnLoop)
|
||||
print(THREAD_NAME,"Loopy")
|
||||
end
|
||||
end)
|
||||
tloop.OnLoop(function(a)
|
||||
print(THREAD_NAME, "Got loop...")
|
||||
end)
|
||||
multi:mainloop()
|
||||
end, tloop:getTransferable())
|
||||
|
||||
local test = tloop:getTransferable()
|
||||
|
||||
multi.print("tloop", tloop.Type)
|
||||
multi.print("tloop.OnLoop", tloop.OnLoop.Type)
|
||||
|
||||
thread:newThread("Proxy Test Thread",function()
|
||||
multi.print("Testing holding on a proxy connection!")
|
||||
thread.hold(tloop.OnLoop)
|
||||
multi.print("Held on proxy connection... once")
|
||||
thread.hold(tloop.OnLoop)
|
||||
multi.print("Held on proxy connection... twice")
|
||||
thread.hold(tloop.OnLoop)
|
||||
multi.print("Held on proxy connection... finally")
|
||||
proxy_test = true
|
||||
end).OnError(print)
|
||||
|
||||
thread:newThread(function()
|
||||
thread.defer(function()
|
||||
multi.print("Something happened!")
|
||||
end)
|
||||
while true do
|
||||
thread.hold(tloop.OnLoop)
|
||||
multi.print(THREAD_NAME,"Local Loopy")
|
||||
end
|
||||
end).OnError(function(...)
|
||||
print("Error",...)
|
||||
end)
|
||||
|
||||
tloop.OnLoop(function()
|
||||
print("OnLoop", THREAD_NAME)
|
||||
end)
|
||||
|
||||
t, val = thread.hold(function()
|
||||
return proxy_test
|
||||
end,{sleep=10})
|
||||
|
||||
if val == multi.TIMEOUT then
|
||||
multi.error("SystemThreadedProcessor/Proxies: Failed")
|
||||
os.exit(1)
|
||||
else
|
||||
multi.success("SystemThreadedProcessor: OK")
|
||||
end
|
||||
|
||||
thread.sleep(2)
|
||||
|
||||
we_good = true
|
||||
multi:Stop() -- Needed in love2d tests to stop the main runner
|
||||
os.exit(0)
|
||||
end)
|
||||
|
||||
multi.OnExit(function(err_or_errorcode)
|
||||
multi.print("EC: ", err_or_errorcode)
|
||||
if not we_good then
|
||||
multi.print("There was an error running some tests!")
|
||||
return
|
||||
else
|
||||
multi.success("Tests complete!")
|
||||
end
|
||||
end)
|
||||
|
||||
multi:mainloop()
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user