Compare commits

...

4 Commits

Author SHA1 Message Date
fe5333512f Updated test file 2021-06-19 20:26:27 -04:00
b2ae7181d6 Fixed issues 2021-06-19 20:24:23 -04:00
2a8b3d095f Patched issue with threaded functions not returning multiple values 2021-06-19 20:14:03 -04:00
68908f093b cleaned up thread files 2020-04-01 10:10:11 -04:00
5 changed files with 18 additions and 34 deletions

View File

@ -1041,13 +1041,13 @@ function multi.holdFor(n,func)
end)
end
local function cleanReturns(...)
local n = select("#", ...)
local returns = {...}
local rets = {}
local ind = 0
for i=n,1,-1 do
for i=#returns,1,-1 do
if returns[i] then
ind=i
ind = i
break
end
end
return unpack(returns,1,ind)

View File

@ -53,11 +53,6 @@ local function INIT(__GlobalLinda,__SleepingLinda)
until __GlobalLinda:get(name)
return __GlobalLinda:get(name)
end
if getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end
function THREAD.getCores()
return THREAD.__CORES
end
@ -92,17 +87,16 @@ local function INIT(__GlobalLinda,__SleepingLinda)
end
_G.THREAD_ID = 0
function THREAD.sleep(n)
math.randomseed(os.time())
__SleepingLinda:receive(n, "__non_existing_variable")
end
function THREAD.hold(n)
local function wait()
math.randomseed(os.time())
while true do
__SleepingLinda:receive(.001, "__non_existing_variable")
local tab = {n()}
if tab[1] then
return unpack(tab)
end
end
repeat
wait()
until n()
end
local GLOBAL = {}
setmetatable(GLOBAL, {

View File

@ -213,9 +213,12 @@ function threads.createStaticTable(n)
)
end
function threads.hold(n)
local dat
while not(dat) do
dat = n()
while true do
love.timer.sleep(.001)
local tab = {n()}
if tab[1] then
return unpack(tab)
end
end
end
return threads

View File

@ -48,35 +48,21 @@ local function INIT(env)
print("Waiting",thread)
return thread.hold(function() return GLOBAL[name] end)
end
if getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end
function THREAD.getCores()
return THREAD.__CORES
end
function THREAD.getConsole()
local c = {}
function c.print(...)
print(...)
end
c.print = print
function c.error(err)
error("ERROR in <"..GLOBAL["$__THREADNAME__"]..">: "..err)
end
return c
end
function THREAD.getThreads()
return {}--GLOBAL.__THREADS__
end
if os.getOS() == "windows" then
THREAD.__CORES = tonumber(os.getenv("NUMBER_OF_PROCESSORS"))
else
THREAD.__CORES = tonumber(io.popen("nproc --all"):read("*n"))
end
function THREAD.kill()
error("Thread was killed!")
return {} --GLOBAL.__THREADS__
end
THREAD.__CORES = thread.__CORES
function THREAD.getName()
return GLOBAL["$THREAD_NAME"]
end

View File

@ -1,3 +1,4 @@
package.path = "./?/init.lua;"..package.path
multi,thread = require("multi"):init()
GLOBAL,THREAD = require("multi.integration.threading"):init() -- Auto detects your enviroment and uses what's available