SystemThreadedExecute (1.8.5)

Added: SystemThreadedExecute
This commit is contained in:
Ryan 2017-07-04 13:53:31 -04:00
parent 854862f2c8
commit e0c72cb8ea
9 changed files with 136 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
# multi Version: 1.8.4 (System Threaded Job Queues) # multi Version: 1.8.5 (System Threaded Execute) Looking into some bugs...
**Note: The changes section has information on how to use the new features as they come out. Why put the infomation twice on the readme?** Also I added a Testing Branch. That Branch will have the latest updates, but those updates may be unstable. I like to keep the master as bug free as possible</br> **Note: The changes section has information on how to use the new features as they come out. Why put the infomation twice on the readme?** Also I added a Testing Branch. That Branch will have the latest updates, but those updates may be unstable. I like to keep the master as bug free as possible</br>
# Note SystemThreadedTable's behavior is not stable! I am looking into this. # Note SystemThreadedTable's behavior is not stable! I am looking into this.
@ -801,6 +801,23 @@ We did it! 1 2 3</br>
Changes Changes
------- -------
Updated from 1.8.4 to 1.8.5
---------------------------
Added:
- SystemThreadedExecute(cmd)
Allows the execution of system calls without hold up. It is possible to do the same using io.popen()! You decide which works best for you!
```lua
local GLOBAL,sThread=require("multi.integration.lanesManager").init()
cmd=multi:newSystemThreadedExecute("SystemThreadedExecuteTest.lua") -- This file is important!
cmd.OnCMDFinished(function(code) -- callback function to grab the exit code... Called when the command goes through
print("Got Code: "..code)
end)
multi:newTLoop(function()
print("...") -- lets show that we aren't being held up
end,1)
multi:mainloop()
```
Updated from 1.8.3 to 1.8.4 Updated from 1.8.3 to 1.8.4
--------------------------- ---------------------------
Added: Added:

View File

@ -0,0 +1,11 @@
package.path="../?.lua;../?/init.lua;"..package.path
local GLOBAL,sThread=require("multi.integration.lanesManager").init()
cmd=multi:newSystemThreadedExecute("SystemThreadedExecuteTest.lua") -- This file is important!
cmd.OnCMDFinished(function(code) -- callback function to grab the exit code... Called when the command goes through
print("Got Code: "..code)
end)
multi:newTLoop(function()
print("...")
end,1)
multi:mainloop()

View File

@ -0,0 +1,14 @@
require("core.Library")
GLOBAL,sThread=require("multi.integration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
require("core.GuiManager")
gui.ff.Color=Color.Black
cmd=multi:newSystemThreadedExecute("C:/SystemThreadedExecuteTest.lua")
cmd.OnCMDFinished(function(code)
print("Got Code: "..code)
end)
multi:newTLoop(function()
print("...")
end,1)
t=gui:newTextLabel("no done yet!",0,0,300,100)
t:centerX()
t:centerY()

View File

@ -45,9 +45,9 @@ function print(...)
end end
end end
multi = {} multi = {}
multi.Version="1.8.4" multi.Version="1.8.5"
multi._VERSION="1.8.4" multi._VERSION="1.8.5"
multi.stage='stable' multi.stage='mostly-stable'
multi.__index = multi multi.__index = multi
multi.Mainloop={} multi.Mainloop={}
multi.Tasks={} multi.Tasks={}

View File

@ -5,7 +5,9 @@ end
multi.integration={} multi.integration={}
multi.integration.love2d={} multi.integration.love2d={}
multi.integration.love2d.ThreadBase=[[ multi.integration.love2d.ThreadBase=[[
__THREADNAME__=({...})[1] tab={...}
__THREADNAME__=tab[2]
__THREADID__=tab[1]
require("love.filesystem") require("love.filesystem")
require("love.system") require("love.system")
require("love.timer") require("love.timer")
@ -32,8 +34,8 @@ function __sync__()
love.timer.sleep(.001) love.timer.sleep(.001)
if type(data)=="string" then if type(data)=="string" then
local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)") local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)")
if name=="__DIEPLZ"..__THREADNAME__.."__" then if name=="__DIEPLZ"..__THREADID__.."__" then
error("Thread: "..__THREADNAME__.." has been stopped!") error("Thread: "..__THREADID__.." has been stopped!")
end end
if cmd=="SYNC" then if cmd=="SYNC" then
__proxy__[name]=resolveType(tp,d) __proxy__[name]=resolveType(tp,d)
@ -268,7 +270,7 @@ function multi:newSystemThread(name,func) -- the main method
c.name=name c.name=name
c.ID=c.name.."<ID|"..randomString(8)..">" c.ID=c.name.."<ID|"..randomString(8)..">"
c.thread=love.thread.newThread(multi.integration.love2d.ThreadBase:gsub("INSERT_USER_CODE",dump(func))) c.thread=love.thread.newThread(multi.integration.love2d.ThreadBase:gsub("INSERT_USER_CODE",dump(func)))
c.thread:start(c.ID) c.thread:start(c.ID,c.name)
function c:kill() function c:kill()
multi.integration.GLOBAL["__DIEPLZ"..self.ID.."__"]="__DIEPLZ"..self.ID.."__" multi.integration.GLOBAL["__DIEPLZ"..self.ID.."__"]="__DIEPLZ"..self.ID.."__"
end end

View File

@ -21,6 +21,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
]] ]]
function multi.randomString(n)
local str = ''
local strings = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}
for i=1,n do
str = str..''..strings[math.random(1,#strings)]
end
return str
end
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
local c={} -- where we will store our object local c={} -- where we will store our object
c.name=name -- set the name this is important for the love2d side c.name=name -- set the name this is important for the love2d side
@ -262,8 +270,8 @@ if love then
self.queueOUT:push({self.jobnum,name,...}) self.queueOUT:push({self.jobnum,name,...})
self.jobnum=self.jobnum+1 self.jobnum=self.jobnum+1
end end
local GLOBAL=multi.integration.GLOBAL -- set up locals incase we are using lanes local GLOBAL=multi.integration.GLOBAL
local sThread=multi.integration.THREAD -- set up locals incase we are using lanes local sThread=multi.integration.THREAD
GLOBAL["__JQ_COUNT__"]=c.cores GLOBAL["__JQ_COUNT__"]=c.cores
for i=1,c.cores do for i=1,c.cores do
multi:newSystemThread("System Threaded Job Queue Worker Thread #"..i,function() multi:newSystemThread("System Threaded Job Queue Worker Thread #"..i,function()
@ -305,3 +313,31 @@ if love then
end end
end end
end end
function multi:newSystemThreadedExecute(cmd)
local c={}
local GLOBAL=multi.integration.GLOBAL -- set up locals incase we are using lanes
local sThread=multi.integration.THREAD -- set up locals incase we are using lanes
local name="Execute_Thread"..multi.randomString(16)
c.name=name
GLOBAL[name.."CMD"]=cmd
multi:newSystemThread(name,function()
if love then -- lets make sure we don't reference upvalues if using love2d
GLOBAL=_G.GLOBAL
sThread=_G.sThread
name=__THREADNAME__ -- global data same as the name we used in this functions creation
end -- Lanes should take the local upvalues ^^^
cmd=sThread.waitFor(name.."CMD")
local ret=os.execute(cmd)
GLOBAL[name.."R"]=ret
end)
c.OnCMDFinished=multi:newConnection()
c.looper=multi:newLoop(function(self)
local ret=GLOBAL[self.link.name.."R"]
if ret then
self.link.OnCMDFinished:Fire(ret)
self:Destroy()
end
end)
c.looper.link=c
return c
end

View File

@ -45,9 +45,9 @@ function print(...)
end end
end end
multi = {} multi = {}
multi.Version="1.8.4" multi.Version="1.8.5"
multi._VERSION="1.8.4" multi._VERSION="1.8.5"
multi.stage='stable' multi.stage='mostly-stable'
multi.__index = multi multi.__index = multi
multi.Mainloop={} multi.Mainloop={}
multi.Tasks={} multi.Tasks={}