V15.2.0 #33

Merged
rayaman merged 75 commits from v15.2.0 into master 2022-04-19 18:45:52 -04:00
3 changed files with 84 additions and 27 deletions
Showing only changes of commit c14a469069 - Show all commits

View File

@ -28,6 +28,7 @@ Added:
Changed: Changed:
--- ---
- Moved `multi:newThread(...)` into the thread interface (`thread:newThread(...)`), code using `multi:newThread(...)` will still work. Also using `process:newThread(...)` binds the thread to the process, meaning if the process the thread is bound to is paused so is the thread.
- multi:mainloop(~~settings~~)/multi:uManager(~~settings~~) no longer takes a settings argument, that has been moved to multi:init(settings) - multi:mainloop(~~settings~~)/multi:uManager(~~settings~~) no longer takes a settings argument, that has been moved to multi:init(settings)
| Setting | Description | | Setting | Description |
---|--- ---|---
@ -105,10 +106,11 @@ Fixed:
- Issue where gettasksdetails() would try to process a destroyed object causing it to crash - Issue where gettasksdetails() would try to process a destroyed object causing it to crash
- Issue with multi.hold() not pumping the mainloop and only the scheduler - Issue with multi.hold() not pumping the mainloop and only the scheduler
ToDo: ToDo:
--- ---
- Work on network parallelism
# Update 15.1.0 - Hold the thread! # Update 15.1.0 - Hold the thread!

View File

@ -27,6 +27,7 @@ local mainloopActive = false
local isRunning = false local isRunning = false
local clock = os.clock local clock = os.clock
local thread = {} local thread = {}
local in_proc = false
if not _G["$multi"] then if not _G["$multi"] then
_G["$multi"] = {multi=multi,thread=thread} _G["$multi"] = {multi=multi,thread=thread}
@ -926,31 +927,46 @@ function multi:newProcessor(name,nothread)
c.Type = "process" c.Type = "process"
c.Active = false or nothread c.Active = false or nothread
c.Name = name or "" c.Name = name or ""
c.process = thread:newThread(function() c.pump = false
while true do c.threads = {}
thread.hold(function() return c.Active end) c.startme = {}
local handler = c:createHandler(c.threads,c.startme)
c.process = multi:newLoop(function()
if c.Active then
c.pump = true
c:uManager() c:uManager()
handler()
c.pump = false
end end
end) end)
c.process.isProcessThread = true c.process.isProcessThread = true
c.process.PID = sandcount c.process.PID = sandcount
c.OnError = c.process.OnError c.OnError = c.process.OnError
function c.run() function c:newThread(name,func,...)
c:uManager() in_proc = c
local t = thread.newThread(c,name,func,...)
in_proc = false
return t
end end
function c:AttachThread(t) function c.run()
-- c.pump = true
c:uManager()
handler()
c.pump = false
end end
function c.Start() function c.Start()
if nothread then return self end
c.Active = true c.Active = true
return self return self
end end
function c.Stop() function c.Stop()
if nothread then return self end
c.Active = false c.Active = false
return self return self
end end
function c:Destroy() function c:Destroy()
self.OnObjectDestroyed:Fire(c) c.Active = false
c.process:Destroy()
end end
return c return c
end end
@ -1237,6 +1253,7 @@ function thread:newThread(name,func,...)
if type(name) == "function" then if type(name) == "function" then
name = "Thread#"..threadCount name = "Thread#"..threadCount
end end
local c={nil,nil,nil,nil,nil,nil,nil} local c={nil,nil,nil,nil,nil,nil,nil}
local env = {self=c} local env = {self=c}
c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil} c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
@ -1300,9 +1317,13 @@ function thread:newThread(name,func,...)
end end
c.Destroy = c.Kill c.Destroy = c.Kill
if self.Type=="process" then
table.insert(threads,c) table.insert(self.threads,c)
table.insert(startme,c) table.insert(self.startme,c)
else
table.insert(threads,c)
table.insert(startme,c)
end
startme_len = #startme startme_len = #startme
globalThreads[c] = multi globalThreads[c] = multi
threadid = threadid + 1 threadid = threadid + 1
@ -1469,7 +1490,6 @@ local co_status = {
--self.setType(ref,self.DestroyedObj) --self.setType(ref,self.DestroyedObj)
end, end,
} }
local count = 0
local handler = coroutine.wrap(function(self) local handler = coroutine.wrap(function(self)
while true do while true do
for start = startme_len,1,-1 do for start = startme_len,1,-1 do
@ -1480,8 +1500,8 @@ local handler = coroutine.wrap(function(self)
yield() yield()
end end
for i=#threads,1,-1 do for i=#threads,1,-1 do
if threads[i] then ref = threads[i]
ref = threads[i] if ref then
task = ref.task task = ref.task
thd = ref.thread thd = ref.thread
ready = ref.__ready ready = ref.__ready
@ -1492,6 +1512,28 @@ local handler = coroutine.wrap(function(self)
end end
end) end)
function multi:createHandler(threads,startme)
return coroutine.wrap(function(self)
while true do
for start = #startme,1,-1 do
_,ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16 = resume(startme[start].thread,unpack(startme[start].startArgs))
co_status[status(startme[start].thread)](startme[start].thread,startme[start],t_none) -- Make sure there was no error
table.remove(startme)
yield()
end
for i=#threads,1,-1 do
ref = threads[i]
if ref then
task = ref.task
thd = ref.thread
ready = ref.__ready
co_status[status(thd)](thd,ref,task,i)
end
yield()
end
end
end)
end
function multi:newService(func) -- Priority managed threads function multi:newService(func) -- Priority managed threads
local c = {} local c = {}

View File

@ -9,18 +9,31 @@ local conn = multi:newConnection()
local test = {} local test = {}
local function bench(_,steps) local function bench(_,steps)
print("Steps/1s: "..steps) print("Steps/1s: "..steps)
os.exit() --os.exit()
end end
proc = multi:newProcessor("Test") proc = multi:newProcessor("Test")
for i = 1,400 do
thread:newThread("Thread: "..i,function()
while true do
thread.sleep(.1)
end
end)
end
proc:benchMark(sleep_for,multi.Priority_Core,"Core:"):OnBench(bench)
while true do proc.Start()
proc.run()
end thread:newThread(function()
thread.sleep(5)
proc.Stop()
thread.sleep(5)
proc.Start()
end)
thread:newThread(function()
while true do
thread.sleep(1)
print("...")
end
end)
proc:newThread(function()
while true do
thread.sleep(1)
print("Testing...")
end
end)
multi:mainloop()