Added some new methods (1.7.6)

More examples
small tweaks
added/modified examples
typos as always
minor bug fixes
some new features, read readme for them
This commit is contained in:
2017-06-26 23:18:38 -04:00
parent 1635a1633c
commit 38f8234d20
16 changed files with 150 additions and 29 deletions
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,32 @@
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
require("proAudioRt") -- an audio library
-- The hosting site with precompiled binaries is down, but here is a link to a archive
-- https://web.archive.org/web/20160907180559/http://viremo.eludi.net:80/proteaAudio/proteaaudiolua.html documentation and downloads are availiable... I also have saved copies just in case :D
-- Music by: myuuji
-- His youtube channel can be found here: https://www.youtube.com/channel/UCiSKnkKCKAQVxMUWpZQobuQ
proAudio.create()
multi:newThread("test",function()
-- simple playlist
sThread.waitFor("song")
print("Playing song 1!")
proAudio.soundPlay(GLOBAL["song"])
sThread.waitFor("song2")
thread.hold(function() sThread.sleep(.001) return proAudio.soundActive()==0 end)
print("Playing song 2!")
proAudio.soundPlay(GLOBAL["song2"])
sThread.waitFor("song3")
thread.hold(function() sThread.sleep(.001) return proAudio.soundActive()==0 end)
print("Playing song 3!")
proAudio.soundPlay(GLOBAL["song3"])
end)
-- loading the audio in another thread is way faster! So lets do that
multi:newSystemThread("test1",function() -- spawns a thread in another lua process
require("proAudioRt")
GLOBAL["song"]=proAudio.sampleFromFile("test.ogg",1,1)
print("Loaded song 1!")
GLOBAL["song2"]=proAudio.sampleFromFile("test2.ogg",1,1)
print("Loaded song 2!")
GLOBAL["song3"]=proAudio.sampleFromFile("test3.ogg",1,1)
print("Loaded song 3!")
end)
multi:mainloop()
Binary file not shown.
Binary file not shown.
Binary file not shown.
-1
View File
@@ -1,6 +1,5 @@
package.path="?/init.lua;?.lua;"..package.path
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
require("multi.threading")
multi:newAlarm(2):OnRing(function(self)
GLOBAL["NumOfCores"]=sThread.getCores()
end)
+2 -5
View File
@@ -1,6 +1,5 @@
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
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() -- loads the lanesManager and includes the entire multi library
local function comma_value(amount)
local formatted = amount
while true do
@@ -40,8 +39,6 @@ multi:newSystemThread("test6",function() -- spawns a thread in another lua proce
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(sThread.waitFor("Bench"),nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end)
multi:mainloop()
end)
multi:newSystemThread("Combiner",function() -- spawns a thread in another lua process
print("Bench: ",comma_value(tostring(sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6"))))
GLOBAL["DONE"]=true
end)
@@ -58,5 +55,5 @@ multi:newThread("test0",function()
end
end
end)
GLOBAL["Bench"]=10
GLOBAL["Bench"]=60
multi:mainloop()
+48
View File
@@ -0,0 +1,48 @@
package.path="?/init.lua;?.lua;"..package.path -- Spawing threads using 1 method and the sThread.getCores() function!
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() -- loads the lanesManager and includes the entire multi library
local function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
GLOBAL["BENCHCOUNT"],GLOBAL["CNUM"],GLOBAL["DONE"]=0,0,0
cores=sThread.getCores()
function benchmark() -- our single function that will be used across a bunch of threads
require("multi.all") -- get the library
local n=GLOBAL["CNUM"]; GLOBAL["CNUM"]=n+1 -- do some math so we can identify which thread is which
multi:benchMark(sThread.waitFor("BENCH"),nil,"Thread "..n+1):OnBench(function(self,c) GLOBAL["BENCHCOUNT"]=GLOBAL["BENCHCOUNT"]+c; GLOBAL["DONE"]=GLOBAL["DONE"]+1; multi:Stop() end)
-- ^ do the bench mark and add to the BENCHCOUNT GLOBAL value, then increment the DONE Value
multi:mainloop()
end
for i=1,cores do -- loop based on the number of cores you have
multi:newSystemThread("test"..i,benchmark) -- create a system thread based on the benchmark
end
multi:newThread("test0",function()
while true do
thread.skip(1)
sThread.sleep(.001)
if GLOBAL["DONE"]==cores then
print(comma_value(tostring(GLOBAL["BENCHCOUNT"])))
os.exit()
end
end
end)
GLOBAL["BENCH"]=10
print("Platform is: ",multi:getPlatform()) -- returns love2d or lanes depending on which platform you are using... If I add more intergrations then this method will be updated! corona sdk may see this library in the future...
multi:mainloop()
--[[ Output on my machine! I am using luajit and have 6 cores on my computer. Your numbers will vary, but it should look something like this
Intergrated Lanes!
Platform is: lanes
Thread 1 62442125 Steps in 10 second(s)!
Thread 2 61379095 Steps in 10 second(s)!
Thread 3 62772502 Steps in 10 second(s)!
Thread 4 62740684 Steps in 10 second(s)!
Thread 5 60926715 Steps in 10 second(s)!
Thread 6 61793175 Steps in 10 second(s)!
372,054,296
]]
+1 -2
View File
@@ -1,6 +1,5 @@
require("core.Library")
require("multi.compat.love2d") -- allows for multitasking and binds my libraies to the love2d engine that i am using
GLOBAL,sThread=require("multi.intergration.loveManager").init() -- load the love2d version of the lanesManager
GLOBAL,sThread=require("multi.intergration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
--IMPORTANT
-- Do not make the above local, this is the one difference that the lanesManager does not have
-- If these are local the functions will have the upvalues put into them that do not exist on the threaded side
@@ -45,7 +45,7 @@ function print(...)
end
end
multi = {}
multi.Version={1,7,5}
multi.Version={1,7,6}
multi.stage='stable'
multi.__index = multi
multi.Mainloop={}
@@ -67,7 +67,7 @@ multi.jobUS=2
multi.clock=os.clock
multi.time=os.time
multi.LinkedPath=multi
mulit.isRunning=false
multi.isRunning=false
multi.queuefinal=function(self)
self:Destroy()
if self.Parent.Mainloop[#self.Parent.Mainloop] then
@@ -239,6 +239,15 @@ end
function multi:getVersion()
return multi.Version[1].."."..multi.Version[2].."."..multi.Version[3]
end
function multi:getPlatform()
if love then
if love.thread then
return "love2d"
end
else
return "lanes"
end
end
--Processor
function multi:getError()
if self.error then
@@ -953,8 +962,8 @@ function multi:newCondition(func)
end
multi.NewCondition=multi.newCondition
function multi:mainloop()
if not mulit.isRunning then
mulit.isRunning=true
if not multi.isRunning then
multi.isRunning=true
for i=1,#self.Tasks do
self.Tasks[i](self)
end
@@ -1020,6 +1029,9 @@ function multi:newEvent(task)
end
end
end
function c:SetTask(func)
self.Task=func
end
function c:OnEvent(func)
table.insert(self.func,func)
end
@@ -31,7 +31,7 @@ end
-- Step 1 get lanes
lanes=require("lanes").configure()
package.path="lua/?/init.lua;lua/?.lua;"..package.path
require("multi.updater") -- get it all and have it on all lanes
require("multi.all") -- get it all and have it on all lanes
local multi=multi
-- Step 2 set up the linda objects
local __GlobalLinda = lanes.linda() -- handles global stuff
@@ -1,3 +1,4 @@
require("multi.compat.love2d")
multi.intergration={}
multi.intergration.love2d={}
multi.intergration.love2d.ThreadBase=[[
@@ -326,6 +327,7 @@ updater:OnUpdate(function(self)
data=multi.intergration.love2d.mainChannel:pop()
end
end)
print("Intergrated Love2d!")
return {
init=function(t)
if t then