updated example

This commit is contained in:
Ryan 2017-06-23 00:45:28 -04:00
parent 4cbb4b0982
commit 2116ed34e5

View File

@ -1,36 +1,51 @@
package.path="?/init.lua;?.lua;"..package.path package.path="?/init.lua;?.lua;"..package.path
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
require("multi.threading") -- obvious copy/paste below with no attempt to clean it up :P
multi:newSystemThread("test1",function() -- spawns a thread in another lua process multi:newSystemThread("test1",function() -- spawns a thread in another lua process
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
multi:benchMark(1,nil,"Thread 1"):OnBench(function(self,c) GLOBAL["T1"]=c multi:Stop() end) multi:benchMark(5,nil,"Thread 1"):OnBench(function(self,c) GLOBAL["T1"]=c multi:Stop() end)
multi:mainloop() multi:mainloop()
end) end)
multi:newSystemThread("test2",function() -- spawns a thread in another lua process multi:newSystemThread("test2",function() -- spawns a thread in another lua process
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
multi:benchMark(1,nil,"Thread 2"):OnBench(function(self,c) GLOBAL["T2"]=c multi:Stop() end) multi:benchMark(5,nil,"Thread 2"):OnBench(function(self,c) GLOBAL["T2"]=c multi:Stop() end)
multi:mainloop() multi:mainloop()
end) end)
multi:newSystemThread("test3",function() -- spawns a thread in another lua process multi:newSystemThread("test3",function() -- spawns a thread in another lua process
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
multi:benchMark(1,nil,"Thread 3"):OnBench(function(self,c) GLOBAL["T3"]=c multi:Stop() end) multi:benchMark(5,nil,"Thread 3"):OnBench(function(self,c) GLOBAL["T3"]=c multi:Stop() end)
multi:mainloop() multi:mainloop()
end) end)
multi:newSystemThread("test4",function() -- spawns a thread in another lua process multi:newSystemThread("test4",function() -- spawns a thread in another lua process
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
multi:benchMark(1,nil,"Thread 4"):OnBench(function(self,c) GLOBAL["T4"]=c multi:Stop() end) multi:benchMark(5,nil,"Thread 4"):OnBench(function(self,c) GLOBAL["T4"]=c multi:Stop() end)
multi:mainloop() multi:mainloop()
end) end)
multi:newSystemThread("test5",function() -- spawns a thread in another lua process multi:newSystemThread("test5",function() -- spawns a thread in another lua process
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
multi:benchMark(1,nil,"Thread 5"):OnBench(function(self,c) GLOBAL["T5"]=c multi:Stop() end) multi:benchMark(5,nil,"Thread 5"):OnBench(function(self,c) GLOBAL["T5"]=c multi:Stop() end)
multi:mainloop() multi:mainloop()
end) end)
multi:newSystemThread("test6",function() -- spawns a thread in another lua process multi:newSystemThread("test6",function() -- spawns a thread in another lua process
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
multi:benchMark(1,nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end) multi:benchMark(5,nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end)
multi:mainloop() multi:mainloop()
end) end)
multi:newSystemThread("test6",function() -- spawns a thread in another lua process multi:newSystemThread("Combiner",function() -- spawns a thread in another lua process
print("Bench: ",sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6")) print("Bench: ",sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6"))
GLOBAL["DONE"]=true
end)
multi:newThread("test0",function()
-- sThread.waitFor("DONE") -- lets hold the main thread completely so we don't eat up cpu
-- os.exit()
-- when the main thread is holding there is a chance that error handling on the system threads may not work!
-- instead we can do this
while true do
thread.skip(1) -- allow error handling to take place... Otherwise lets keep the main thread running on the low
sThread.sleep(.001) -- Sleeping for .001 is a greeat way to keep cpu usage down. Make sure if you aren't doing work to rest. Abuse the hell out of GLOBAL if you need to :P
if GLOBAL["DONE"] then
os.exit()
end
end
end) end)
multi:mainloop() multi:mainloop()