diff --git a/changes.md b/changes.md index c2cc9b0..7ce4fa0 100644 --- a/changes.md +++ b/changes.md @@ -4,7 +4,7 @@ Table of contents --- -# Update 14.2.0 - Destroy! +# Update 14.2.0 - Ending it all! Full Update Showcase --- ```lua diff --git a/multi/init.lua b/multi/init.lua index 3671406..6794a62 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -964,6 +964,12 @@ function multi:scheduleJob(time,func) end -- Threading stuff +local initT = false +local threadCount = 0 +local threadid = 0 +thread.__threads = {} +local threads = thread.__threads +local Gref = _G multi.GlobalVariables={} local dFunc = function() return true end local dRef = {nil,nil,nil} @@ -971,10 +977,20 @@ thread.requests = {} function thread.request(t,cmd,...) thread.requests[t.thread] = {cmd,{...}} end +function thread.getRunningThread() + local t = coroutine.running() + if t then + for i,v in pairs(threads) do + if t==v.thread then + return v + end + end + end +end function thread._Requests() local t = thread.requests[coroutine.running()] - thread.requests[coroutine.running()] = nil if t then + thread.requests[coroutine.running()] = nil local cmd,args = t[1],t[2] thread[cmd](unpack(args)) end @@ -984,6 +1000,7 @@ function thread.exec(func) end function thread.sleep(n) thread._Requests() + thread.getRunningThread().lastSleep = clock() dRef[1] = "_sleep_" dRef[2] = n or 0 return coroutine.yield(dRef) @@ -1150,17 +1167,6 @@ function thread.testFor(name,_val,sym) end) return thread.get(name) end -function multi.print(...) - if multi.defaultSettings.print then - print(...) - end -end -local initT = false -local threadCount = 0 -local threadid = 0 -thread.__threads = {} -local threads = thread.__threads -local Gref = _G function multi:newThread(name,func,...) multi.OnLoad:Fire() local func = func or name @@ -1468,6 +1474,8 @@ function multi:newService(func) -- Priority managed threads elseif math.abs(n)==2 then ap = math.abs(p-1)*32+1 task = thread.skip + elseif math.abs(n)==3 then + -- This is a time based pirority manager. Things that take long to run get end return c end @@ -2261,6 +2269,12 @@ else thread.__CORES=tonumber(io.popen("nproc --all"):read("*n")) end +function multi.print(...) + if multi.defaultSettings.print then + print(...) + end +end + multi.GetType=multi.getType multi.IsPaused=multi.isPaused multi.IsActive=multi.isActive diff --git a/multi/integration/lanesManager/init.lua b/multi/integration/lanesManager/init.lua index 62d35da..995cf0e 100644 --- a/multi/integration/lanesManager/init.lua +++ b/multi/integration/lanesManager/init.lua @@ -84,16 +84,17 @@ function multi:newSystemThread(name, func, ...) c.priority = THREAD.Priority_Normal local args = {...} multi:newThread(function() - print("I am here!") c.thread = lanes.gen(table.concat(c.loadString,","), { - globals={ - THREAD_NAME=name, - THREAD_ID=count, - THREAD = THREAD, - GLOBAL = GLOBAL, - _Console = __ConsoleLinda - },priority=c.priority}, func)(unpack(args)) + globals={ -- Set up some globals + THREAD_NAME=name, + THREAD_ID=count, + THREAD = THREAD, + GLOBAL = GLOBAL, + _Console = __ConsoleLinda + }, + priority=c.priority + },func)(unpack(args)) thread.kill() end) count = count + 1 diff --git a/test.dat b/test.dat deleted file mode 100644 index 1bff574..0000000 Binary files a/test.dat and /dev/null differ diff --git a/test.lua b/test.lua index cf56d09..c3af6ca 100644 --- a/test.lua +++ b/test.lua @@ -1,7 +1,19 @@ package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path multi,thread = require("multi"):init() -t = multi:newThread(function() - print("Hello!") - os.exit() +local GLOBAL,THREAD = require("multi.integration.lanesManager"):init() +func = THREAD:newFunction(function(test) + print(test) + THREAD.sleep(1) + return "Hello World!" end) +func("Did it work").connect(function(...) + print(...) + --os.exit() +end) +local serv = multi:newService(function(self,data) + local name = thread.getRunningThread().Name + print(name) +end) +serv.Start() +serv.SetPriority(multi.Priority_Low) multi:lightloop() \ No newline at end of file