V15.3.0 #46

Merged
rayaman merged 85 commits from v15.3.0 into network_parallelism_test_branch 2022-06-11 23:41:07 -04:00
5 changed files with 73 additions and 14 deletions
Showing only changes of commit 40dd293bf8 - Show all commits

View File

@ -28,6 +28,7 @@ local function getOS()
return "unix" return "unix"
end end
end end
local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda) local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
local THREAD = {} local THREAD = {}
THREAD.Priority_Core = 3 THREAD.Priority_Core = 3
@ -37,12 +38,15 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
THREAD.Priority_Below_Normal = -1 THREAD.Priority_Below_Normal = -1
THREAD.Priority_Low = -2 THREAD.Priority_Low = -2
THREAD.Priority_Idle = -3 THREAD.Priority_Idle = -3
function THREAD.set(name, val) function THREAD.set(name, val)
__GlobalLinda:set(name, val) __GlobalLinda:set(name, val)
end end
function THREAD.get(name) function THREAD.get(name)
return __GlobalLinda:get(name) return __GlobalLinda:get(name)
end end
function THREAD.waitFor(name) function THREAD.waitFor(name)
local function wait() local function wait()
math.randomseed(os.time()) math.randomseed(os.time())
@ -53,14 +57,17 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
until __GlobalLinda:get(name) until __GlobalLinda:get(name)
return __GlobalLinda:get(name) return __GlobalLinda:get(name)
end end
if getOS() == "windows" then if getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end end
function THREAD.getCores() function THREAD.getCores()
return THREAD.__CORES return THREAD.__CORES
end end
function THREAD.getConsole() function THREAD.getConsole()
local c = {} local c = {}
c.queue = _Console c.queue = _Console
@ -73,32 +80,41 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
end end
return c return c
end end
function THREAD.getThreads() function THREAD.getThreads()
return GLOBAL.__THREADS__ return GLOBAL.__THREADS__
end end
if os.getOS() == "windows" then if os.getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end end
function THREAD.kill() -- trigger the lane destruction function THREAD.kill() -- trigger the lane destruction
error("Thread was killed!\1") error("Thread was killed!\1")
end end
function THREAD.getName() function THREAD.getName()
return THREAD_NAME return THREAD_NAME
end end
function THREAD.getID() function THREAD.getID()
return THREAD_ID return THREAD_ID
end end
function THREAD.pushStatus(...) function THREAD.pushStatus(...)
local args = {...} local args = {...}
__StatusLinda:send(nil,THREAD_ID, args) __StatusLinda:send(nil,THREAD_ID, args)
end end
_G.THREAD_ID = 0 _G.THREAD_ID = 0
function THREAD.sleep(n) function THREAD.sleep(n)
math.randomseed(os.time()) math.randomseed(os.time())
__SleepingLinda:receive(n, "__non_existing_variable") __SleepingLinda:receive(n, "__non_existing_variable")
end end
function THREAD.hold(n) function THREAD.hold(n)
local function wait() local function wait()
math.randomseed(os.time()) math.randomseed(os.time())
@ -108,6 +124,7 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
wait() wait()
until n() until n()
end end
local GLOBAL = {} local GLOBAL = {}
setmetatable(GLOBAL, { setmetatable(GLOBAL, {
__index = function(t, k) __index = function(t, k)
@ -119,6 +136,7 @@ local function INIT(__GlobalLinda, __SleepingLinda, __StatusLinda)
}) })
return GLOBAL, THREAD return GLOBAL, THREAD
end end
return {init = function(g,s,st) return {init = function(g,s,st)
return INIT(g,s,st) return INIT(g,s,st)
end} end}

View File

@ -28,12 +28,15 @@ require("love.thread")
local socket = require("socket") local socket = require("socket")
local multi, thread = require("multi").init() local multi, thread = require("multi").init()
local threads = {} local threads = {}
function threads.loadDump(d) function threads.loadDump(d)
return loadstring(d:getString()) return loadstring(d:getString())
end end
function threads.dump(func) function threads.dump(func)
return love.data.newByteData(string.dump(func)) return love.data.newByteData(string.dump(func))
end end
local fRef = {"func",nil} local fRef = {"func",nil}
local function manage(channel, value) local function manage(channel, value)
channel:clear() channel:clear()
@ -45,6 +48,7 @@ local function manage(channel, value)
channel:push(value) channel:push(value)
end end
end end
local function RandomVariable(length) local function RandomVariable(length)
local res = {} local res = {}
math.randomseed(socket.gettime()*10000) math.randomseed(socket.gettime()*10000)
@ -53,12 +57,14 @@ local function RandomVariable(length)
end end
return table.concat(res) return table.concat(res)
end end
local GNAME = "__GLOBAL_" local GNAME = "__GLOBAL_"
local proxy = {} local proxy = {}
function threads.set(name,val) function threads.set(name,val)
if not proxy[name] then proxy[name] = love.thread.getChannel(GNAME..name) end if not proxy[name] then proxy[name] = love.thread.getChannel(GNAME..name) end
proxy[name]:performAtomic(manage, val) proxy[name]:performAtomic(manage, val)
end end
function threads.get(name) function threads.get(name)
if not proxy[name] then proxy[name] = love.thread.getChannel(GNAME..name) end if not proxy[name] then proxy[name] = love.thread.getChannel(GNAME..name) end
local dat = proxy[name]:peek() local dat = proxy[name]:peek()
@ -68,6 +74,7 @@ function threads.get(name)
return dat return dat
end end
end end
function threads.waitFor(name) function threads.waitFor(name)
if thread.isThread() then if thread.isThread() then
return thread.hold(function() return thread.hold(function()
@ -83,23 +90,28 @@ function threads.waitFor(name)
end end
return dat return dat
end end
function threads.package(name,val) function threads.package(name,val)
local init = val.init local init = val.init
val.init=threads.dump(val.init) val.init=threads.dump(val.init)
GLOBAL[name]=val GLOBAL[name]=val
val.init=init val.init=init
end end
function threads.getCores() function threads.getCores()
return love.system.getProcessorCount() return love.system.getProcessorCount()
end end
function threads.kill() function threads.kill()
error("Thread Killed!\1") error("Thread Killed!\1")
end end
function THREAD.pushStatus(...) function THREAD.pushStatus(...)
local status_channel = love.thread.getChannel("__"..__THREADID__.."__MULTI__STATUS_CHANNEL__") local status_channel = love.thread.getChannel("__"..__THREADID__.."__MULTI__STATUS_CHANNEL__")
local args = {...} local args = {...}
status_channel:push(__THREADID__, args) status_channel:push(__THREADID__, args)
end end
function threads.getThreads() function threads.getThreads()
local t = {} local t = {}
for i=1,GLOBAL["__THREAD_COUNT"] do for i=1,GLOBAL["__THREAD_COUNT"] do
@ -107,18 +119,23 @@ function threads.getThreads()
end end
return t return t
end end
function threads.getThread(n) function threads.getThread(n)
return GLOBAL["__THREAD_"..n] return GLOBAL["__THREAD_"..n]
end end
function threads.getName() function threads.getName()
return __THREADNAME__ return __THREADNAME__
end end
function threads.getID() function threads.getID()
return __THREADID__ return __THREADID__
end end
function threads.sleep(n) function threads.sleep(n)
love.timer.sleep(n) love.timer.sleep(n)
end end
function threads.getGlobal() function threads.getGlobal()
return setmetatable({}, return setmetatable({},
{ {
@ -131,6 +148,7 @@ function threads.getGlobal()
} }
) )
end end
function threads.createTable(n) function threads.createTable(n)
local _proxy = {} local _proxy = {}
local function set(name,val) local function set(name,val)
@ -157,6 +175,7 @@ function threads.createTable(n)
} }
) )
end end
function threads.getConsole() function threads.getConsole()
local c = {} local c = {}
c.queue = love.thread.getChannel("__CONSOLE__") c.queue = love.thread.getChannel("__CONSOLE__")
@ -169,6 +188,7 @@ function threads.getConsole()
end end
return c return c
end end
if not ISTHREAD then if not ISTHREAD then
local clock = os.clock local clock = os.clock
local lastproc = clock() local lastproc = clock()
@ -187,6 +207,7 @@ if not ISTHREAD then
end end
end) end)
end end
function threads.createStaticTable(n) function threads.createStaticTable(n)
local __proxy = {} local __proxy = {}
local function set(name,val) local function set(name,val)
@ -218,10 +239,12 @@ function threads.createStaticTable(n)
} }
) )
end end
function threads.hold(n) function threads.hold(n)
local dat local dat
while not(dat) do while not(dat) do
dat = n() dat = n()
end end
end end
return threads return threads

View File

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
]] ]]
package.path = "?/init.lua;?.lua;" .. package.path package.path = "?/init.lua;?.lua;" .. package.path
local multi, thread = require("multi").init() local multi, thread = require("multi"):init()
if multi.integration then if multi.integration then
return { return {
@ -32,7 +32,7 @@ if multi.integration then
} }
end end
local GLOBAL, THREAD = require("multi.integration.pesudoManager.threads"):init(thread) local GLOBAL, THREAD = require("multi.integration.pesudoManager.threads").init(thread)
function multi:canSystemThread() -- We are emulating system threading function multi:canSystemThread() -- We are emulating system threading
return true return true
@ -41,6 +41,7 @@ end
function multi:getPlatform() function multi:getPlatform()
return "pesudo" return "pesudo"
end end
local function split(str) local function split(str)
local tab = {} local tab = {}
for word in string.gmatch(str, '([^,]+)') do for word in string.gmatch(str, '([^,]+)') do
@ -48,13 +49,15 @@ local function split(str)
end end
return tab return tab
end end
THREAD.newFunction=thread.newFunction THREAD.newFunction=thread.newFunction
local id = 0 local id = 0
function multi:newSystemThread(name,func,...) function multi:newSystemThread(name,func,...)
GLOBAL["$THREAD_NAME"] = name GLOBAL["$THREAD_NAME"] = name
GLOBAL["$__THREADNAME__"] = name GLOBAL["$__THREADNAME__"] = name
GLOBAL["$THREAD_ID"] = id GLOBAL["$THREAD_ID"] = id
--GLOBAL["$thread"] = thread GLOBAL["$thread"] = thread
local env = { local env = {
GLOBAL = GLOBAL, GLOBAL = GLOBAL,
THREAD = THREAD, THREAD = THREAD,
@ -75,6 +78,7 @@ function multi:newSystemThread(name,func,...)
end) end)
id = id + 1 id = id + 1
end end
THREAD.newSystemThread = multi.newSystemThread THREAD.newSystemThread = multi.newSystemThread
-- System threads as implemented here cannot share memory, but use a message passing system. -- System threads as implemented here cannot share memory, but use a message passing system.
-- An isolated thread allows us to mimic that behavior so if access data from the "main" thread happens things will not work. This behavior is in line with how the system threading works -- An isolated thread allows us to mimic that behavior so if access data from the "main" thread happens things will not work. This behavior is in line with how the system threading works

View File

@ -28,7 +28,9 @@ local function getOS()
return "unix" return "unix"
end end
end end
local function INIT(env,thread)
local function INIT(thread)
print("T",thread.sleep)
local THREAD = {} local THREAD = {}
local GLOBAL = {} local GLOBAL = {}
THREAD.Priority_Core = 3 THREAD.Priority_Core = 3
@ -38,23 +40,29 @@ local function INIT(env,thread)
THREAD.Priority_Below_Normal = -1 THREAD.Priority_Below_Normal = -1
THREAD.Priority_Low = -2 THREAD.Priority_Low = -2
THREAD.Priority_Idle = -3 THREAD.Priority_Idle = -3
function THREAD.set(name, val) function THREAD.set(name, val)
GLOBAL[name] = val GLOBAL[name] = val
end end
function THREAD.get(name) function THREAD.get(name)
return GLOBAL[name] return GLOBAL[name]
end end
function THREAD.waitFor(name) function THREAD.waitFor(name)
return thread.hold(function() return GLOBAL[name] end) return thread.hold(function() return GLOBAL[name] end)
end end
if getOS() == "windows" then if getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end end
function THREAD.getCores() function THREAD.getCores()
return THREAD.__CORES return THREAD.__CORES
end end
function THREAD.getConsole() function THREAD.getConsole()
local c = {} local c = {}
function c.print(...) function c.print(...)
@ -65,33 +73,38 @@ local function INIT(env,thread)
end end
return c return c
end end
function THREAD.getThreads() function THREAD.getThreads()
return {}--GLOBAL.__THREADS__ return {}--GLOBAL.__THREADS__
end end
THREAD.pushstatus = thread.pushstatus
THREAD.pushStatus = thread.pushStatus
if os.getOS() == "windows" then if os.getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS")) THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n")) THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end end
function THREAD.kill() function THREAD.kill()
error("Thread was killed!") error("Thread was killed!")
end end
function THREAD.getName() function THREAD.getName()
return GLOBAL["$THREAD_NAME"] return GLOBAL["$THREAD_NAME"]
end end
function THREAD.getID() function THREAD.getID()
return GLOBAL["$THREAD_ID"] return GLOBAL["$THREAD_ID"]
end end
THREAD.pushstatus
function THREAD.sleep(n) THREAD.sleep = thread.sleep
thread.sleep(n)
end THREAD.hold = thread.hold
function THREAD.hold(n)
return thread.hold(n)
end
return GLOBAL, THREAD return GLOBAL, THREAD
end end
return {init = function(thread) return {init = function(thread)
return INIT(nil,thread) return INIT(thread)
end} end}

View File

@ -1,6 +1,6 @@
package.path = "./?/init.lua;"..package.path package.path = "./?/init.lua;"..package.path
multi, thread = require("multi"):init() multi, thread = require("multi"):init()
GLOBAL, THREAD = require("multi.integration.lanesManager"):init() GLOBAL, THREAD = require("multi.integration.pesudoManager"):init()
func = THREAD:newFunction(function(count) func = THREAD:newFunction(function(count)
print("Starting Status test: ",count) print("Starting Status test: ",count)
@ -13,6 +13,7 @@ func = THREAD:newFunction(function(count)
end end
return "Done" return "Done"
end) end)
local ret = func(10) local ret = func(10)
local ret2 = func(15) local ret2 = func(15)
local ret3 = func(20) local ret3 = func(20)