From 2116ed34e56b92a7c6f75ee690043a2de36d6c0c Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 23 Jun 2017 00:45:28 -0400 Subject: [PATCH] updated example --- lanesintergratetest2.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lanesintergratetest2.lua b/lanesintergratetest2.lua index f727a3b..c034d15 100644 --- a/lanesintergratetest2.lua +++ b/lanesintergratetest2.lua @@ -1,36 +1,51 @@ package.path="?/init.lua;?.lua;"..package.path 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 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() end) 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 - 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() end) 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 - 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() end) 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 - 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() end) 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 - 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() end) 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 - 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() 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")) + 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) multi:mainloop()