diff --git a/.gitignore b/.gitignore index d5aac56..eebfe4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.code-workspace *.dat -*test* -test* -*test \ No newline at end of file +test.lua +test2.lua +test3.lua \ No newline at end of file diff --git a/multi/integration/lanesManager/init.lua b/multi/integration/lanesManager/init.lua index 9526c4f..afb66ec 100644 --- a/multi/integration/lanesManager/init.lua +++ b/multi/integration/lanesManager/init.lua @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] package.path = "?/init.lua;?.lua;" .. package.path -multi, thread = require("multi"):init() -- get it all and have it on all lanes +local multi, thread = require("multi"):init() -- get it all and have it on all lanes if multi.integration then -- This allows us to call the lanes manager from supporting modules without a hassle return { init = function() @@ -53,7 +53,7 @@ multi:newLoop(function() print(unpack(data)) end end) -local GLOBAL,THREAD = {},{}-- require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda) +local GLOBAL,THREAD = require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda) local count = 1 local started = false local livingThreads = {} @@ -66,7 +66,7 @@ function THREAD:newFunction(func,holdme) end function multi:newSystemThread(name, func, ...) - --multi.InitSystemThreadErrorHandler() + multi.InitSystemThreadErrorHandler() local rand = math.random(1, 10000000) local return_linda = lanes.linda() local c = {} @@ -94,7 +94,6 @@ function multi:newSystemThread(name, func, ...) local has_error = true return_linda:set("returns",{func(...)}) has_error = false - --error("thread killed") print("Thread ending") end)(...) count = count + 1 @@ -106,7 +105,7 @@ function multi:newSystemThread(name, func, ...) table.insert(multi.SystemThreads, c) c.OnDeath = multi:newConnection() c.OnError = multi:newConnection() - --GLOBAL["__THREADS__"] = livingThreads + GLOBAL["__THREADS__"] = livingThreads return c end @@ -126,7 +125,7 @@ function multi.InitSystemThreadErrorHandler() livingThreads[temp.Id] = {false, temp.Name} temp.alive = false temp.OnDeath:Fire(temp,nil,unpack(({temp.returns:receive(0, "returns")})[2])) - --GLOBAL["__THREADS__"] = livingThreads + GLOBAL["__THREADS__"] = livingThreads --print(temp.thread:cancel(10,true)) table.remove(threads, i) elseif status == "running" then @@ -137,19 +136,19 @@ function multi.InitSystemThreadErrorHandler() livingThreads[temp.Id] = {false, temp.Name} temp.alive = false temp.OnError:Fire(temp,nil,unpack(temp.returns:receive(0,"returns"))) - --GLOBAL["__THREADS__"] = livingThreads + GLOBAL["__THREADS__"] = livingThreads table.remove(threads, i) elseif status == "cancelled" then livingThreads[temp.Id] = {false, temp.Name} temp.alive = false temp.OnError:Fire(temp,nil,"thread_cancelled") - --GLOBAL["__THREADS__"] = livingThreads + GLOBAL["__THREADS__"] = livingThreads table.remove(threads, i) elseif status == "killed" then livingThreads[temp.Id] = {false, temp.Name} temp.alive = false temp.OnError:Fire(temp,nil,"thread_killed") - --GLOBAL["__THREADS__"] = livingThreads + GLOBAL["__THREADS__"] = livingThreads table.remove(threads, i) end end diff --git a/test3.lua b/test3.lua index e0bb33f..ac2e32f 100644 --- a/test3.lua +++ b/test3.lua @@ -1,13 +1,47 @@ -lanes = require("lanes").configure({allocator="protected",verbose_errors=""}) local multi,thread = require("multi"):init() +local GLOBAL,THREAD = require("multi.integration.threading"):init() function sleep(n) if n > 0 then os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL") end end +-- local GLOBAL,THREAD = {},{}-- require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda) +-- local count = 1 +-- local started = false +-- local livingThreads = {} +-- local threads = {} +-- multi.SystemThreads = {} +-- function multi:newSystemThread(name, func, ...) +-- --multi.InitSystemThreadErrorHandler() +-- local rand = math.random(1, 10000000) +-- local return_linda = lanes.linda() +-- local c = {} +-- c.name = name +-- c.Name = name +-- c.Id = count +-- c.loadString = {"base","package","os","io","math","table","string","coroutine"} +-- livingThreads[count] = {true, name} +-- c.returns = return_linda +-- c.Type = "sthread" +-- c.creationTime = os.clock() +-- c.alive = true +-- c.priority = THREAD.Priority_Normal +-- c.thread = lanes.gen("*",func)(...) +-- count = count + 1 +-- function c:kill() +-- self.thread:cancel() +-- multi.print("Thread: '" .. self.name .. "' has been stopped!") +-- self.alive = false +-- end +-- table.insert(multi.SystemThreads, c) +-- c.OnDeath = multi:newConnection() +-- c.OnError = multi:newConnection() +-- GLOBAL["__THREADS__"] = livingThreads +-- return c +-- end -lanes.gen("*",function() - print("Hello!") -end)() +multi:newSystemThread("test",function() + print("Hello World!") +end) multi:newThread("Test thread",function() while true do