Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0021cba673 | |||
| 14852f0a70 | |||
| 087736c947 | |||
| 548de44c9e | |||
| fab307d8a3 | |||
| 4865045053 | |||
| 68908f093b |
@ -1,4 +1,4 @@
|
||||
# Multi Version: 15.0.0 Fake it, until you make it
|
||||
# Multi Version: 14.3.0 Fake it, until you make it
|
||||
**Key Changes**
|
||||
- Emulating system threading on a single thread
|
||||
|
||||
|
||||
10
changes.md
10
changes.md
@ -2,9 +2,13 @@
|
||||
|
||||
Table of contents
|
||||
---
|
||||
[Update 14.2.0 - Bloatware Removed](#update-1420---bloatware-removed)</br>[Update 14.1.0 - A whole new world of possibilities](#update-1410---a-whole-new-world-of-possibilities)</br>[Update 14.0.0 - Consistency, Additions and Stability](#update-1400---consistency-additions-and-stability)</br>[Update 13.1.0 - Bug fixes and features added](#update-1310---bug-fixes-and-features-added)</br>[Update 13.0.0 - Added some documentation, and some new features too check it out!](#update-1300---added-some-documentation-and-some-new-features-too-check-it-out)</br>[Update 12.2.2 - Time for some more bug fixes!](#update-1222---time-for-some-more-bug-fixes)</br>[Update 12.2.1 - Time for some bug fixes!](#update-1221---time-for-some-bug-fixes)</br>[Update 12.2.0 - The chains of binding](#update-1220---the-chains-of-binding)</br>[Update 12.1.0 - Threads just can't hold on anymore](#update-1210---threads-just-cant-hold-on-anymore)</br>[Update: 12.0.0 - Big update (Lots of additions some changes)](#update-1200---big-update-lots-of-additions-some-changes)</br>[Update: 1.11.1 - Small Clarification on Love](#update-1111---small-clarification-on-love)</br>[Update: 1.11.0](#update-1110)</br>[Update: 1.10.0](#update-1100)</br>[Update: 1.9.2](#update-192)</br>[Update: 1.9.1 - Threads can now argue](#update-191---threads-can-now-argue)</br>[Update: 1.9.0](#update-190)</br>[Update: 1.8.7](#update-187)</br>[Update: 1.8.6](#update-186)</br>[Update: 1.8.5](#update-185)</br>[Update: 1.8.4](#update-184)</br>[Update: 1.8.3 - Mainloop recieves some needed overhauling](#update-183---mainloop-recieves-some-needed-overhauling)</br>[Update: 1.8.2](#update-182)</br>[Update: 1.8.1](#update-181)</br>[Update: 1.7.6](#update-176)</br>[Update: 1.7.5](#update-175)</br>[Update: 1.7.4](#update-174)</br>[Update: 1.7.3](#update-173)</br>[Update: 1.7.2](#update-172)</br>[Update: 1.7.1 - Bug Fixes Only](#update-171---bug-fixes-only)</br>[Update: 1.7.0 - Threading the systems](#update-170---threading-the-systems)</br>[Update: 1.6.0](#update-160)</br>[Update: 1.5.0](#update-150)</br>[Update: 1.4.1 (4/10/2017) - First Public release of the library](#update-141-4102017---first-public-release-of-the-library)</br>[Update: 1.4.0 (3/20/2017)](#update-140-3202017)</br>[Update: 1.3.0 (1/29/2017)](#update-130-1292017)</br>[Update: 1.2.0 (12.31.2016)](#update-120-12312016)</br>[Update: 1.1.0](#update-110)</br>[Update: 1.0.0](#update-100)</br>[Update: 0.6.3](#update-063)</br>[Update: 0.6.2](#update-062)</br>[Update: 0.6.1-6](#update-061-6)</br>[Update: 0.5.1-6](#update-051-6)</br>[Update: 0.4.1](#update-041)</br>[Update: 0.3.0 - The update that started it all](#update-030---the-update-that-started-it-all)</br>[Update: EventManager 2.0.0](#update-eventmanager-200)</br>[Update: EventManager 1.2.0](#update-eventmanager-120)</br>[Update: EventManager 1.1.0](#update-eventmanager-110)</br>[Update: EventManager 1.0.0 - Error checking](#update-eventmanager-100---error-checking)</br>[Version: EventManager 0.0.1 - In The Beginning things were very different](#version-eventmanager-001---in-the-beginning-things-were-very-different)
|
||||
[Update 14.3.0 - The art of faking it](#update-1430---the-art-of-faking-it)</br>[Update 14.2.0 - Bloatware Removed](#update-1420---bloatware-removed)</br>[Update 14.1.0 - A whole new world of possibilities](#update-1410---a-whole-new-world-of-possibilities)</br>[Update 14.0.0 - Consistency, Additions and Stability](#update-1400---consistency-additions-and-stability)</br>[Update 13.1.0 - Bug fixes and features added](#update-1310---bug-fixes-and-features-added)</br>[Update 13.0.0 - Added some documentation, and some new features too check it out!](#update-1300---added-some-documentation-and-some-new-features-too-check-it-out)</br>[Update 12.2.2 - Time for some more bug fixes!](#update-1222---time-for-some-more-bug-fixes)</br>[Update 12.2.1 - Time for some bug fixes!](#update-1221---time-for-some-bug-fixes)</br>[Update 12.2.0 - The chains of binding](#update-1220---the-chains-of-binding)</br>[Update 12.1.0 - Threads just can't hold on anymore](#update-1210---threads-just-cant-hold-on-anymore)</br>[Update: 12.0.0 - Big update (Lots of additions some changes)](#update-1200---big-update-lots-of-additions-some-changes)</br>[Update: 1.11.1 - Small Clarification on Love](#update-1111---small-clarification-on-love)</br>[Update: 1.11.0](#update-1110)</br>[Update: 1.10.0](#update-1100)</br>[Update: 1.9.2](#update-192)</br>[Update: 1.9.1 - Threads can now argue](#update-191---threads-can-now-argue)</br>[Update: 1.9.0](#update-190)</br>[Update: 1.8.7](#update-187)</br>[Update: 1.8.6](#update-186)</br>[Update: 1.8.5](#update-185)</br>[Update: 1.8.4](#update-184)</br>[Update: 1.8.3 - Mainloop recieves some needed overhauling](#update-183---mainloop-recieves-some-needed-overhauling)</br>[Update: 1.8.2](#update-182)</br>[Update: 1.8.1](#update-181)</br>[Update: 1.7.6](#update-176)</br>[Update: 1.7.5](#update-175)</br>[Update: 1.7.4](#update-174)</br>[Update: 1.7.3](#update-173)</br>[Update: 1.7.2](#update-172)</br>[Update: 1.7.1 - Bug Fixes Only](#update-171---bug-fixes-only)</br>[Update: 1.7.0 - Threading the systems](#update-170---threading-the-systems)</br>[Update: 1.6.0](#update-160)</br>[Update: 1.5.0](#update-150)</br>[Update: 1.4.1 (4/10/2017) - First Public release of the library](#update-141-4102017---first-public-release-of-the-library)</br>[Update: 1.4.0 (3/20/2017)](#update-140-3202017)</br>[Update: 1.3.0 (1/29/2017)](#update-130-1292017)</br>[Update: 1.2.0 (12.31.2016)](#update-120-12312016)</br>[Update: 1.1.0](#update-110)</br>[Update: 1.0.0](#update-100)</br>[Update: 0.6.3](#update-063)</br>[Update: 0.6.2](#update-062)</br>[Update: 0.6.1-6](#update-061-6)</br>[Update: 0.5.1-6](#update-051-6)</br>[Update: 0.4.1](#update-041)</br>[Update: 0.3.0 - The update that started it all](#update-030---the-update-that-started-it-all)</br>[Update: EventManager 2.0.0](#update-eventmanager-200)</br>[Update: EventManager 1.2.0](#update-eventmanager-120)</br>[Update: EventManager 1.1.0](#update-eventmanager-110)</br>[Update: EventManager 1.0.0 - Error checking](#update-eventmanager-100---error-checking)</br>[Version: EventManager 0.0.1 - In The Beginning things were very different](#version-eventmanager-001---in-the-beginning-things-were-very-different)
|
||||
|
||||
# Update 14.3.0 - The art of faking it
|
||||
14.3.1
|
||||
---
|
||||
- Fixed issue with threads
|
||||
|
||||
# Update 15.0.0 - The art of faking it
|
||||
Full Update Showcase
|
||||
---
|
||||
```lua
|
||||
@ -39,7 +43,7 @@ Added:
|
||||
|
||||
Fixed:
|
||||
---
|
||||
- lanesManager THREAD:get(STRING: name) not returning the value
|
||||
- lanesManager THREAD:get(STRING: name) not returning anything
|
||||
|
||||
# Update 14.2.0 - Bloatware Removed
|
||||
Full Update Showcase
|
||||
|
||||
130
multi/init.lua
130
multi/init.lua
@ -30,7 +30,7 @@ if not _G["$multi"] then
|
||||
_G["$multi"] = {multi=multi,thread=thread}
|
||||
end
|
||||
|
||||
multi.Version = "15.0.0"
|
||||
multi.Version = "14.3.1"
|
||||
multi.stage = "stable"
|
||||
multi.Name = "multi.root"
|
||||
multi.Mainloop = {}
|
||||
@ -1072,13 +1072,21 @@ function thread:newFunction(func,holdme)
|
||||
return temp
|
||||
end
|
||||
end
|
||||
-- A cross version way to set enviroments, not the same as fenv though
|
||||
function multi.setEnv(func,env)
|
||||
local f = string.dump(func)
|
||||
local chunk = load(f,"env","bt",env)
|
||||
return chunk
|
||||
end
|
||||
|
||||
function multi:newThread(name,func,...)
|
||||
multi.OnLoad:Fire()
|
||||
local func = func or name
|
||||
if type(name) == "function" then
|
||||
name = "Thread#"..threadCount
|
||||
end
|
||||
local env = {}
|
||||
local c={}
|
||||
local env = {self=c}
|
||||
setmetatable(env,{
|
||||
__index = Gref,
|
||||
__newindex = function(t,k,v)
|
||||
@ -1090,7 +1098,117 @@ function multi:newThread(name,func,...)
|
||||
end
|
||||
})
|
||||
setfenv(func,env)
|
||||
c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
|
||||
c.startArgs = {...}
|
||||
c.ref={}
|
||||
c.Name=name
|
||||
c.thread=coroutine.create(func)
|
||||
c.sleep=1
|
||||
c.Type="thread"
|
||||
c.TID = threadid
|
||||
c.firstRunDone=false
|
||||
c.timer=multi:newTimer()
|
||||
c._isPaused = false
|
||||
c.returns = {}
|
||||
c.OnError = multi:newConnection(true,nil,true)
|
||||
c.OnDeath = multi:newConnection(true,nil,true)
|
||||
function c:isPaused()
|
||||
return self._isPaused
|
||||
end
|
||||
local resumed = false
|
||||
function c:Pause()
|
||||
if not self._isPaused then
|
||||
thread.request(self,"exec",function()
|
||||
thread.hold(function()
|
||||
return resumed
|
||||
end)
|
||||
resumed = false
|
||||
self._isPaused = false
|
||||
end)
|
||||
self._isPaused = true
|
||||
end
|
||||
return self
|
||||
end
|
||||
function c:Resume()
|
||||
resumed = true
|
||||
return self
|
||||
end
|
||||
function c:Kill()
|
||||
thread.request(self,"kill")
|
||||
return self
|
||||
end
|
||||
c.Destroy = c.Kill
|
||||
function c.ref:send(name,val)
|
||||
ret=coroutine.yield({Name=name,Value=val})
|
||||
end
|
||||
function c.ref:get(name)
|
||||
return self.Globals[name]
|
||||
end
|
||||
function c.ref:kill()
|
||||
dRef[1] = "_kill_"
|
||||
dRef[2] = "I Was killed by You!"
|
||||
err = coroutine.yield(dRef)
|
||||
if err then
|
||||
error("Failed to kill a thread! Exiting...")
|
||||
end
|
||||
end
|
||||
function c.ref:sleep(n)
|
||||
if type(n)=="function" then
|
||||
ret=thread.hold(n)
|
||||
elseif type(n)=="number" then
|
||||
ret=thread.sleep(tonumber(n) or 0)
|
||||
else
|
||||
error("Invalid Type for sleep!")
|
||||
end
|
||||
end
|
||||
function c.ref:syncGlobals(v)
|
||||
self.Globals=v
|
||||
end
|
||||
table.insert(threads,c)
|
||||
if initT==false then
|
||||
multi.initThreads()
|
||||
end
|
||||
c.creationTime = os.clock()
|
||||
threadid = threadid + 1
|
||||
self:create(c)
|
||||
return c
|
||||
end
|
||||
function multi:newISOThread(name,func,...)
|
||||
multi.OnLoad:Fire()
|
||||
local func = func or name
|
||||
if type(name) == "function" then
|
||||
name = "Thread#"..threadCount
|
||||
end
|
||||
local env = {
|
||||
thread = thread,
|
||||
multi = multi,
|
||||
coroutine = coroutine,
|
||||
debug = debug,
|
||||
io = io,
|
||||
math = math,
|
||||
os = os,
|
||||
package = package,
|
||||
string = string,
|
||||
table = table,
|
||||
utf8 = utf8
|
||||
}
|
||||
for i,v in pairs(_G) do
|
||||
if tostring(v):match("builtin") then
|
||||
env[i]=v
|
||||
end
|
||||
end
|
||||
setmetatable(env,{
|
||||
__newindex = function(t,k,v)
|
||||
if type(v)=="function" then
|
||||
rawset(t,k,thread:newFunction(v))
|
||||
else
|
||||
Gref[k]=v
|
||||
end
|
||||
end
|
||||
})
|
||||
local func = multi.setEnv(func,env)
|
||||
local c={}
|
||||
env.self = c
|
||||
c.TempRets = {nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}
|
||||
c.startArgs = {...}
|
||||
c.ref={}
|
||||
@ -1255,9 +1373,11 @@ function multi.initThreads(justThreads)
|
||||
multi.scheduler:OnLoop(function(self)
|
||||
for i=#threads,1,-1 do
|
||||
if threads[i].isError then
|
||||
threads[i].OnError:Fire(threads[i],unpack(threads[i].TempRets))
|
||||
multi.setType(threads[i],multi.DestroyedObj)
|
||||
table.remove(threads,i)
|
||||
if coroutine.status(threads[i].thread)=="dead" then
|
||||
threads[i].OnError:Fire(threads[i],unpack(threads[i].TempRets))
|
||||
multi.setType(threads[i],multi.DestroyedObj)
|
||||
table.remove(threads,i)
|
||||
end
|
||||
end
|
||||
if threads[i] and not threads[i].__started then
|
||||
if coroutine.running() ~= threads[i].thread then
|
||||
|
||||
@ -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, {
|
||||
|
||||
@ -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
|
||||
@ -47,48 +47,33 @@ local function INIT()
|
||||
function THREAD.waitFor(name)
|
||||
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 <"..__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 THREAD_NAME
|
||||
local t = thread.getRunningThread()
|
||||
return t.Name
|
||||
end
|
||||
function THREAD.getID()
|
||||
return THREAD_ID
|
||||
local t = thread.getRunningThread()
|
||||
return t.TID
|
||||
end
|
||||
_G.THREAD_ID = 0
|
||||
function THREAD.sleep(n)
|
||||
thread.sleep(n)
|
||||
end
|
||||
function THREAD.hold(n)
|
||||
return thread.hold(n)
|
||||
end
|
||||
THREAD.kill = thread.kill
|
||||
THREAD.sleep = thread.sleep
|
||||
THREAD.hold = thread.hold
|
||||
return GLOBAL, THREAD
|
||||
end
|
||||
return {init = function()
|
||||
|
||||
44
rockspecs/multi-14.3-0.rockspec
Normal file
44
rockspecs/multi-14.3-0.rockspec
Normal file
@ -0,0 +1,44 @@
|
||||
package = "multi"
|
||||
version = "14.3-0"
|
||||
source = {
|
||||
url = "git://github.com/rayaman/multi.git",
|
||||
tag = "v14.3.0",
|
||||
}
|
||||
description = {
|
||||
summary = "Lua Multi tasking library",
|
||||
detailed = [[
|
||||
This library contains many methods for multi tasking. Features non coroutine based multi-tasking, coroutine based multi-tasking, and system threading (Requires use of an integration).
|
||||
Check github for how to use.
|
||||
]],
|
||||
homepage = "https://github.com/rayaman/multi",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1",
|
||||
"lanes",
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
["multi"] = "multi/init.lua",
|
||||
|
||||
["multi.compat.love2d"] = "multi/compat/love2d.lua",
|
||||
|
||||
["multi.integration.lanesManager"] = "multi/integration/lanesManager/init.lua",
|
||||
["multi.integration.lanesManager.extensions"] = "multi/integration/lanesManager/extensions.lua",
|
||||
["multi.integration.lanesManager.threads"] = "multi/integration/lanesManager/threads.lua",
|
||||
|
||||
["multi.integration.pesudoManager"] = "multi/integration/pesudoManager/init.lua",
|
||||
["multi.integration.pesudoManager.extensions"] = "multi/integration/pesudoManager/extensions.lua",
|
||||
["multi.integration.pesudoManager.threads"] = "multi/integration/pesudoManager/threads.lua",
|
||||
["multi.integration.threading"] = "multi/integration/threading.lua",
|
||||
|
||||
["multi.integration.loveManager"] = "multi/integration/loveManager/init.lua",
|
||||
["multi.integration.loveManager.extensions"] = "multi/integration/loveManager/extensions.lua",
|
||||
["multi.integration.loveManager.threads"] = "multi/integration/loveManager/threads.lua",
|
||||
|
||||
["multi.integration.luvitManager"] = "multi/integration/luvitManager.lua",
|
||||
|
||||
--["multi.integration.networkManager"] = "multi/integration/networkManager.lua",
|
||||
}
|
||||
}
|
||||
13
test.lua
13
test.lua
@ -2,6 +2,19 @@ package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
|
||||
multi,thread = require("multi"):init()
|
||||
GLOBAL,THREAD = require("multi.integration.pesudoManager"):init()
|
||||
|
||||
multi:newThread(function()
|
||||
while true do
|
||||
thread.sleep(1)
|
||||
print("hello!")
|
||||
end
|
||||
end)
|
||||
multi:newThread(function()
|
||||
while true do
|
||||
thread.sleep(1)
|
||||
print("hello!")
|
||||
--prrint("hehe")
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
multi:mainloop({print=true})
|
||||
Loading…
x
Reference in New Issue
Block a user