From 5cceaef837db4e6be7d8b4c9085cc12b075de920 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Thu, 13 Feb 2020 12:54:46 -0500 Subject: [PATCH] Working on stability features. --- changes.md | 3 +- multi/integration/lanesManager/init.lua | 4 +- test.lua | 71 +++++++------------------ 3 files changed, 24 insertions(+), 54 deletions(-) diff --git a/changes.md b/changes.md index 2a78aeb..b0f516d 100644 --- a/changes.md +++ b/changes.md @@ -80,9 +80,10 @@ multi:mainloop() - thread:newFunction(func,holup) -- Added an argument holdme to always force the threaded funcion to wait. Meaning you don't need to tell it to func().wait() or func().connect() - multi:newConnection(protect,callback,kill) -- Added the kill argument. Makes connections work sort of like a stack. Pop off the connections as they get called. So a one time connection handler. - I'm not sure callback has been documented in any form. callback gets called each and everytime conn:Fire() gets called! As well as being triggered for each connfunc that is part of the connection. +- modified the lanes manager to create globals GLOBAL and THREAD when a thread is started. This way you are now able to more closely mirror code between lanes and love. As of right now parity between both enviroments is now really good. Upvalues being copied by default in lanes is something that I will not try and mirror in love. It's better to pass what you need as arguments, this way you can keep things consistant. looping thorugh upvalues and sterlizing them and sending them are very complex and slow opperations. # Added: -- THREAD:newFunction(func,holup) -- A system threaded based variant to thread:newFunction(func,holup) +- THREAD:newFunction(func,holup) -- A system threaded based variant to thread:newFunction(func,holup) works the same way. Though this should only be used for intensive functions! Calling a STfunction has a decent amount of overhead, use wisely. System threaded jobqueue may be a better choice depending on what you are planning on doing. - multi:loveloop() -- Handles the run function for love2d as well as run the multi mainloop. - multi.OnLoad(func) -- A special connection that allows you to connect to the an event that triggers when the multi engine starts! This is slightly different from multi.PreLoad(func) Which connects before any variables have been set up in the multi table, before any settings are cemented into the core. In most cases they will operate exactly the same. This is a feature that was created with module creators in mind. This way they can have code be loaded and managed before the main loop starts. - multi.OnExit(func) -- A special connection that allows you to connect onto the lua state closing event. diff --git a/multi/integration/lanesManager/init.lua b/multi/integration/lanesManager/init.lua index 6e187e5..46fedac 100644 --- a/multi/integration/lanesManager/init.lua +++ b/multi/integration/lanesManager/init.lua @@ -77,7 +77,9 @@ function multi:newSystemThread(name, func, ...) local args = {...} c.thread = lanes.gen(table.concat(c.loadString,","),{globals={ THREAD_NAME=name, - THREAD_ID=count + THREAD_ID=count, + THREAD = THREAD, + GLOBAL = GLOBAL },priority=c.priority}, func)(unpack(args)) count = count + 1 function c:kill() diff --git a/test.lua b/test.lua index 88409a2..8a321ab 100644 --- a/test.lua +++ b/test.lua @@ -1,58 +1,25 @@ package.path="?/init.lua;?.lua;"..package.path multi,thread = require("multi"):init() -multi.OnLoad(function() - print("Code Loaded!") -end) -multi:setTimeout(function() - print("here we are!") -end,2) -local t -co = 0 +--GLOBAL,THREAD = require("multi.integration.lanesManager"):init() +-- local co = 0 +-- multi.OnLoad(function() +-- print("Code Loaded!") +-- end) multi.OnExit(function(n) - print("Code Exited: ".. os.clock()-t .." Count: ".. co) + print("Code Exited!") end) -test = thread:newFunction(function() - thread.sleep(1) - return 1,math.random(2,100) -end) -multi:newThread(function() - while true do - thread.sleep(.1) - print("!") - end -end) -multi:newThread(function() - t = os.clock() - while true do - thread.skip() - co = co + 1 - end -end) -example = {} -setmetatable(example,{ - __newindex = function(t,k,v) - print("Inside metamethod",t,k,v) - local a,b = test().wait() - print("We did it!",a,b) - rawset(t,k,v) - end, - __index = thread:newFunction(function(t,k,v) - thread.sleep(1) - return "You got a string" - end,true) -}) -example["test"] = "We set a variable!" -print(example["test"]) -print(example.hi) -c,d = test().wait() -print(c,d) -a,b = 6,7 -multi:newThread(function() - a,b = test() - print("Waited:",a,b) - test().connect(function(a,b) - print("Connected:",a,b) - os.exit() - end) +-- multi:newThread(function() +-- t = os.clock() +-- while true do +-- thread.skip() +-- co = co + 1 +-- end +-- end) +-- multi:setTimeout(function() +-- os.exit() +-- end,5) +multi:benchMark(1):OnBench(function(...) + print(...) + os.exit() end) multi:mainloop() \ No newline at end of file