Cleaning up some stuff
This commit is contained in:
parent
3e795ede05
commit
498aa1f9aa
19
changes.md
19
changes.md
@ -12,20 +12,7 @@ Added:
|
||||
-- handle:Pause()
|
||||
-- handle:Resume()
|
||||
-- handle:Kill()
|
||||
- Basic Thread error checking.
|
||||
When creating a coroutine based thread with multi:newThread(), the library will attempt to scan through the butecode and check for while loops and the use of thread.* This is only done at thread creation. It isn't perfect, but the goal is to print a warning message that the thread may hang the multi library. This also has some flaws, if a thread function calls another function that has code that may hang the program, this quick check does not see that! Perhaps this is something I can tackle in the future.
|
||||
```lua
|
||||
package.path="?/init.lua;?.lua;"..package.path
|
||||
multi = require("multi")
|
||||
a=0
|
||||
multi:newThread("Test",function()
|
||||
while true do
|
||||
a=a+1
|
||||
end
|
||||
end)
|
||||
multi:mainloop()
|
||||
-- Output: Warning! The thread created: <Test> contains a while loop which may not be confugured properly with thread.* If your code seems to hang this may be the reason!
|
||||
```
|
||||
|
||||
Fixed:
|
||||
- Minor bug with multi:newThread() in how names and functions were managed
|
||||
- Major bug with the system thread handler. Saw healthy threads as dead ones
|
||||
@ -38,6 +25,10 @@ Changed:
|
||||
- thread.hold() -- As part of the memory leaks that I had to fix thread.hold() is slightly different. This change shouldn't impact previous code at all, but thread.hold() can not only return at most 7 arguments!
|
||||
- You should notice some faster code execution from threads, the changes improve preformance of threads greatly. They are now much faster than before!
|
||||
|
||||
Removed:
|
||||
- multi:threadloop()
|
||||
-- After some reworking to how threads are managed, this feature is no longer needed
|
||||
|
||||
# Tasks Details Table format
|
||||
```
|
||||
{
|
||||
|
||||
@ -345,7 +345,6 @@ function multi:getTasksDetails(t)
|
||||
table.insert(str,{v.Type:sub(1,1):upper()..v.Type:sub(2,-1)..name,multi.Round(os.clock()-v.creationTime,3),self.PriorityResolve[v.Priority],v.TID})
|
||||
end
|
||||
for v,i in pairs(multi.PausedObjects) do
|
||||
if v.Type~="event" then
|
||||
local name = v.Name or ""
|
||||
if name~="" then
|
||||
name = " <"..name..">"
|
||||
@ -353,7 +352,6 @@ function multi:getTasksDetails(t)
|
||||
count = count + 1
|
||||
table.insert(str,{v.Type:sub(1,1):upper()..v.Type:sub(2,-1)..name,multi.Round(os.clock()-v.creationTime,3),self.PriorityResolve[v.Priority],v.TID})
|
||||
end
|
||||
end
|
||||
if count == 0 then
|
||||
table.insert(str,{"Currently no processes running!","","",""})
|
||||
end
|
||||
@ -393,10 +391,8 @@ function multi:getTasksDetails(t)
|
||||
table.insert(str.Tasks,{Link = v, Type=v.Type,Name=v.Name,Uptime=os.clock()-v.creationTime,Priority=self.PriorityResolve[v.Priority],TID = v.TID})
|
||||
end
|
||||
for v,i in pairs(multi.PausedObjects) do
|
||||
if v.Type~="event" then
|
||||
table.insert(str.Tasks,{Link = v, Type=v.Type,Name=v.Name,Uptime=os.clock()-v.creationTime,Priority=self.PriorityResolve[v.Priority],TID = v.TID})
|
||||
end
|
||||
end
|
||||
for i=1,#multi.scheduler.Threads do
|
||||
table.insert(str.Threads,{Uptime = os.clock()-multi.scheduler.Threads[i].creationTime,Name = multi.scheduler.Threads[i].Name,Link = multi.scheduler.Threads[i],TID = multi.scheduler.Threads[i].TID})
|
||||
end
|
||||
@ -1555,12 +1551,6 @@ function multi:newThread(name,func)
|
||||
if type(name) == "function" then
|
||||
name = "Thread#"..threadCount
|
||||
end
|
||||
local g=string.dump(func)
|
||||
if g:find("K") and not g:find("thread") then
|
||||
print("Warning! The thread created: <"..name.."> contains a while loop which may not be confugured properly with thread.* If your code seems to hang this may be the reason!")
|
||||
else
|
||||
multi.print("Should be safe")
|
||||
end
|
||||
local c={}
|
||||
c.ref={}
|
||||
c.Name=name
|
||||
@ -1893,72 +1883,6 @@ function multi:newHyperThreadedProcess(name)
|
||||
return c
|
||||
end
|
||||
-- Multi runners
|
||||
function multi:threadloop(settings)
|
||||
multi.scheduler:Destroy() -- destroy is an interesting thing... if you dont set references to nil, then you only remove it from the mainloop
|
||||
local Threads=multi:linkDomain("Threads")
|
||||
local Globals=multi:linkDomain("Globals")
|
||||
local counter=0
|
||||
local tick = 0
|
||||
while true do
|
||||
tick = tick + 1
|
||||
if tick == 1024 then
|
||||
tick = 0
|
||||
multi:uManager(settings)
|
||||
end
|
||||
counter=counter+1
|
||||
for i=#Threads,1,-1 do
|
||||
ret={}
|
||||
if coroutine.status(Threads[i].thread)=="dead" then
|
||||
table.remove(Threads,i)
|
||||
else
|
||||
if Threads[i].timer:Get()>=Threads[i].sleep then
|
||||
if Threads[i].firstRunDone==false then
|
||||
Threads[i].firstRunDone=true
|
||||
Threads[i].timer:Start()
|
||||
_,ret=coroutine.resume(Threads[i].thread,Threads[i].ref)
|
||||
else
|
||||
_,ret=coroutine.resume(Threads[i].thread,Globals)
|
||||
end
|
||||
if _==false then
|
||||
multi.OnError:Fire(Threads[i],"Error in thread: <"..Threads[i].Name.."> "..ret)
|
||||
end
|
||||
if ret==true or ret==false then
|
||||
ret={}
|
||||
end
|
||||
end
|
||||
if ret then
|
||||
if ret[1]=="_kill_" then
|
||||
table.remove(Threads,i)
|
||||
elseif ret[1]=="_sleep_" then
|
||||
Threads[i].timer:Reset()
|
||||
Threads[i].sleep=ret[2]
|
||||
elseif ret[1]=="_skip_" then
|
||||
Threads[i].timer:Reset()
|
||||
Threads[i].sleep=math.huge
|
||||
local event=multi:newEvent(function(evnt) return counter>=evnt.counter end)
|
||||
event.link=Threads[i]
|
||||
event.counter=counter+ret[2]
|
||||
event:OnEvent(function(evnt)
|
||||
evnt.link.sleep=0
|
||||
evnt:Destroy()
|
||||
end)
|
||||
elseif ret[1]=="_hold_" then
|
||||
Threads[i].timer:Reset()
|
||||
Threads[i].sleep=math.huge
|
||||
local event=multi:newEvent(ret[2])
|
||||
event.link=Threads[i]
|
||||
event:OnEvent(function(evnt)
|
||||
evnt.link.sleep=0
|
||||
evnt:Destroy()
|
||||
end)
|
||||
elseif ret.Name then
|
||||
Globals[ret.Name]=ret.Value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function multi:mainloop(settings)
|
||||
multi.defaultSettings = settings or multi.defaultSettings
|
||||
self.uManager=self.uManagerRef
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user