Fixed some bugs, a little more testing needed

This commit is contained in:
Ryan Ward 2022-04-19 18:39:30 -04:00
parent 440995b1c8
commit b0ab40d410
7 changed files with 31 additions and 53 deletions

View File

@ -18,8 +18,9 @@ Progress is being made in [v15.3.0](https://github.com/rayaman/multi/tree/v15.3.
INSTALLING INSTALLING
---------- ----------
Link to dependencies: Link to optional dependencies:
[lanes](https://github.com/LuaLanes/lanes) [lanes](https://github.com/LuaLanes/lanes)
[love2d](https://love2d.org/)
To install copy the multi folder into your environment and you are good to go</br> To install copy the multi folder into your environment and you are good to go</br>
If you want to use the system threads, then you'll need to install lanes or love2d game engine! If you want to use the system threads, then you'll need to install lanes or love2d game engine!
@ -32,7 +33,7 @@ https://discord.gg/U8UspuA
Planned features/TODO Planned features/TODO
--------------------- ---------------------
- [ ] Create test suite - [ ] Create test suite (In progress, mostly done)
- [ ] Network Parallelism rework - [ ] Network Parallelism rework
Usage: [Check out the documentation for more info](https://github.com/rayaman/multi/blob/master/Documentation.md) Usage: [Check out the documentation for more info](https://github.com/rayaman/multi/blob/master/Documentation.md)
@ -40,7 +41,8 @@ Usage: [Check out the documentation for more info](https://github.com/rayaman/mu
```lua ```lua
local multi, thread = require("multi"):init() local multi, thread = require("multi"):init()
GLOBAL, THREAD = require("multi.integration.lanesManager"):init() GLOBAL, THREAD = require("multi.integration.threading"):init()
multi:newSystemThread("System Thread",function() multi:newSystemThread("System Thread",function()
while true do while true do
THREAD.sleep(.1) THREAD.sleep(.1)
@ -48,6 +50,7 @@ multi:newSystemThread("System Thread",function()
THREAD.kill() THREAD.kill()
end end
end) end)
multi:newThread("Coroutine Based Thread",function() multi:newThread("Coroutine Based Thread",function()
while true do while true do
io.write("Hello") io.write("Hello")
@ -55,12 +58,15 @@ multi:newThread("Coroutine Based Thread",function()
thread.kill() thread.kill()
end end
end) end)
multi:newTLoop(function(loop) multi:newTLoop(function(loop)
print("!") print("!")
loop:Destroy() loop:Destroy()
os.exit() os.exit()
end,.3) end,.3)
multi:mainloop() multi:mainloop()
--[[ --[[
while true do while true do
multi:uManager() multi:uManager()

View File

@ -1164,7 +1164,6 @@ function thread:newFunctionBase(generator,holdme)
if thread.isThread() then if thread.isThread() then
return thread.hold(function() return thread.hold(function()
if err then if err then
print("ERROR",err)
return multi.NIL, err return multi.NIL, err
elseif rets then elseif rets then
return cleanReturns((rets[1] or multi.NIL),rets[2],rets[3],rets[4],rets[5],rets[6],rets[7],rets[8],rets[9],rets[10],rets[11],rets[12],rets[13],rets[14],rets[15],rets[16]) return cleanReturns((rets[1] or multi.NIL),rets[2],rets[3],rets[4],rets[5],rets[6],rets[7],rets[8],rets[9],rets[10],rets[11],rets[12],rets[13],rets[14],rets[15],rets[16])
@ -1344,7 +1343,7 @@ function thread:newISOThread(name,func,_env,...)
name = "Thread#"..threadCount name = "Thread#"..threadCount
end end
local func = isolateFunction(func,env) local func = isolateFunction(func,env)
return thread:newThread(name,func) return thread:newThread(name,func,...)
end end
multi.newThread = thread.newThread multi.newThread = thread.newThread

View File

@ -92,6 +92,9 @@ function multi:newSystemThread(name, func, ...)
has_error = false has_error = false
end)(...) end)(...)
count = count + 1 count = count + 1
function c:getName()
return c.Name
end
function c:kill() function c:kill()
self.thread:cancel() self.thread:cancel()
self.alive = false self.alive = false

View File

@ -61,6 +61,9 @@ function multi:newSystemThread(name,func,...)
GLOBAL["__THREAD_"..c.ID] = {ID=c.ID, Name=c.name, Thread=c.thread} GLOBAL["__THREAD_"..c.ID] = {ID=c.ID, Name=c.name, Thread=c.thread}
GLOBAL["__THREAD_COUNT"] = THREAD_ID GLOBAL["__THREAD_COUNT"] = THREAD_ID
THREAD_ID=THREAD_ID + 1 THREAD_ID=THREAD_ID + 1
function c:getName()
return c.name
end
thread:newThread(function() thread:newThread(function()
if name:find("TempSystemThread") then if name:find("TempSystemThread") then
local status_channel = love.thread.getChannel("__"..c.ID.."__MULTI__STATUS_CHANNEL__") local status_channel = love.thread.getChannel("__"..c.ID.."__MULTI__STATUS_CHANNEL__")

View File

@ -50,7 +50,8 @@ local function split(str)
return tab return tab
end end
THREAD.newFunction=thread.newFunction local tab = [[_VERSION,io,os,require,load,debug,assert,collectgarbage,error,getfenv,getmetatable,ipairs,loadstring,module,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,math,coroutine,string,table]]
tab = split(tab)
local id = 0 local id = 0
function multi:newSystemThread(name,func,...) function multi:newSystemThread(name,func,...)
@ -67,23 +68,28 @@ function multi:newSystemThread(name,func,...)
thread = thread thread = thread
} }
local tab = [[_VERSION,io,os,require,load,debug,assert,collectgarbage,error,getfenv,getmetatable,ipairs,loadstring,module,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,math,coroutine,string,table]]
tab = split(tab)
for i = 1,#tab do for i = 1,#tab do
env[tab[i]] = _G[tab[i]] env[tab[i]] = _G[tab[i]]
end end
--setmetatable(env,{__index=env})
thread:newISOThread(name,func,env,...).OnError(function(self,msg) local th = thread:newISOThread(name,func,env,...)
print("ERROR:",msg)
end)
id = id + 1 id = id + 1
return th
end end
THREAD.newSystemThread = multi.newSystemThread 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
print("Integrated Pesudo Threading!") function THREAD:newFunction(func,holdme)
return thread:newFunctionBase(function(...)
return multi:newSystemThread("TempSystemThread",func,...)
end,holdme)()
end
multi.print("Integrated Pesudo 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

@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
]] ]]
local function getOS() local function getOS()
if package.config:sub(1, 1) == "\\" then if package.config:sub(1, 1) == "\\" then
return "windows" return "windows"
@ -30,7 +31,6 @@ local function getOS()
end end
local function INIT(thread) local function INIT(thread)
print("T",thread.sleep)
local THREAD = {} local THREAD = {}
local GLOBAL = {} local GLOBAL = {}
THREAD.Priority_Core = 3 THREAD.Priority_Core = 3

View File

@ -1,39 +0,0 @@
package.path = "./?.lua;?/init.lua;"..package.path
local multi,thread = require("multi"):init()
--[[ Testing...
Before AVG: 522386
Test 1 AVG:
]]
local sleep_for = 1
local conn = multi:newConnection()
local test = {}
local function bench(_,steps)
print("Steps/1s: "..steps)
--os.exit()
end
proc = multi:newProcessor("Test")
proc.Start()
multi:newTLoop(function()
end,1)
-- thread:newThread(function()
-- while true do
-- thread.sleep(1)
-- print("Proc: ".. tostring(proc.isActive()))
-- end
-- end)
local func = proc:newFunction(function(a,b,c)
print("Testing proc functions!")
error("Testing")
return "Please", "Smile", 123
end)
func("Some","tests","needed").connect(function(a,b,c)
print("Return",a,b,c)
end)
multi:mainloop()