V15.2.0 #33
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
*.dat
|
*.dat
|
||||||
*test*
|
test.lua
|
||||||
test*
|
test2.lua
|
||||||
*test
|
test3.lua
|
||||||
@ -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
|
||||||
multi, thread = require("multi"):init() -- get it all and have it on all lanes
|
local multi, thread = require("multi"):init() -- get it all and have it on all lanes
|
||||||
if multi.integration then -- This allows us to call the lanes manager from supporting modules without a hassle
|
if multi.integration then -- This allows us to call the lanes manager from supporting modules without a hassle
|
||||||
return {
|
return {
|
||||||
init = function()
|
init = function()
|
||||||
@ -53,7 +53,7 @@ multi:newLoop(function()
|
|||||||
print(unpack(data))
|
print(unpack(data))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
local GLOBAL,THREAD = {},{}-- require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda)
|
local GLOBAL,THREAD = require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda)
|
||||||
local count = 1
|
local count = 1
|
||||||
local started = false
|
local started = false
|
||||||
local livingThreads = {}
|
local livingThreads = {}
|
||||||
@ -66,7 +66,7 @@ function THREAD:newFunction(func,holdme)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function multi:newSystemThread(name, func, ...)
|
function multi:newSystemThread(name, func, ...)
|
||||||
--multi.InitSystemThreadErrorHandler()
|
multi.InitSystemThreadErrorHandler()
|
||||||
local rand = math.random(1, 10000000)
|
local rand = math.random(1, 10000000)
|
||||||
local return_linda = lanes.linda()
|
local return_linda = lanes.linda()
|
||||||
local c = {}
|
local c = {}
|
||||||
@ -94,7 +94,6 @@ function multi:newSystemThread(name, func, ...)
|
|||||||
local has_error = true
|
local has_error = true
|
||||||
return_linda:set("returns",{func(...)})
|
return_linda:set("returns",{func(...)})
|
||||||
has_error = false
|
has_error = false
|
||||||
--error("thread killed")
|
|
||||||
print("Thread ending")
|
print("Thread ending")
|
||||||
end)(...)
|
end)(...)
|
||||||
count = count + 1
|
count = count + 1
|
||||||
@ -106,7 +105,7 @@ function multi:newSystemThread(name, func, ...)
|
|||||||
table.insert(multi.SystemThreads, c)
|
table.insert(multi.SystemThreads, c)
|
||||||
c.OnDeath = multi:newConnection()
|
c.OnDeath = multi:newConnection()
|
||||||
c.OnError = multi:newConnection()
|
c.OnError = multi:newConnection()
|
||||||
--GLOBAL["__THREADS__"] = livingThreads
|
GLOBAL["__THREADS__"] = livingThreads
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -126,7 +125,7 @@ function multi.InitSystemThreadErrorHandler()
|
|||||||
livingThreads[temp.Id] = {false, temp.Name}
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
temp.alive = false
|
temp.alive = false
|
||||||
temp.OnDeath:Fire(temp,nil,unpack(({temp.returns:receive(0, "returns")})[2]))
|
temp.OnDeath:Fire(temp,nil,unpack(({temp.returns:receive(0, "returns")})[2]))
|
||||||
--GLOBAL["__THREADS__"] = livingThreads
|
GLOBAL["__THREADS__"] = livingThreads
|
||||||
--print(temp.thread:cancel(10,true))
|
--print(temp.thread:cancel(10,true))
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
elseif status == "running" then
|
elseif status == "running" then
|
||||||
@ -137,19 +136,19 @@ function multi.InitSystemThreadErrorHandler()
|
|||||||
livingThreads[temp.Id] = {false, temp.Name}
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
temp.alive = false
|
temp.alive = false
|
||||||
temp.OnError:Fire(temp,nil,unpack(temp.returns:receive(0,"returns")))
|
temp.OnError:Fire(temp,nil,unpack(temp.returns:receive(0,"returns")))
|
||||||
--GLOBAL["__THREADS__"] = livingThreads
|
GLOBAL["__THREADS__"] = livingThreads
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
elseif status == "cancelled" then
|
elseif status == "cancelled" then
|
||||||
livingThreads[temp.Id] = {false, temp.Name}
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
temp.alive = false
|
temp.alive = false
|
||||||
temp.OnError:Fire(temp,nil,"thread_cancelled")
|
temp.OnError:Fire(temp,nil,"thread_cancelled")
|
||||||
--GLOBAL["__THREADS__"] = livingThreads
|
GLOBAL["__THREADS__"] = livingThreads
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
elseif status == "killed" then
|
elseif status == "killed" then
|
||||||
livingThreads[temp.Id] = {false, temp.Name}
|
livingThreads[temp.Id] = {false, temp.Name}
|
||||||
temp.alive = false
|
temp.alive = false
|
||||||
temp.OnError:Fire(temp,nil,"thread_killed")
|
temp.OnError:Fire(temp,nil,"thread_killed")
|
||||||
--GLOBAL["__THREADS__"] = livingThreads
|
GLOBAL["__THREADS__"] = livingThreads
|
||||||
table.remove(threads, i)
|
table.remove(threads, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
42
test3.lua
42
test3.lua
@ -1,13 +1,47 @@
|
|||||||
lanes = require("lanes").configure({allocator="protected",verbose_errors=""})
|
|
||||||
local multi,thread = require("multi"):init()
|
local multi,thread = require("multi"):init()
|
||||||
|
local GLOBAL,THREAD = require("multi.integration.threading"):init()
|
||||||
|
|
||||||
function sleep(n)
|
function sleep(n)
|
||||||
if n > 0 then os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL") end
|
if n > 0 then os.execute("ping -n " .. tonumber(n+1) .. " localhost > NUL") end
|
||||||
end
|
end
|
||||||
|
-- local GLOBAL,THREAD = {},{}-- require("multi.integration.lanesManager.threads").init(__GlobalLinda,__SleepingLinda)
|
||||||
|
-- local count = 1
|
||||||
|
-- local started = false
|
||||||
|
-- local livingThreads = {}
|
||||||
|
-- local threads = {}
|
||||||
|
-- multi.SystemThreads = {}
|
||||||
|
-- function multi:newSystemThread(name, func, ...)
|
||||||
|
-- --multi.InitSystemThreadErrorHandler()
|
||||||
|
-- local rand = math.random(1, 10000000)
|
||||||
|
-- local return_linda = lanes.linda()
|
||||||
|
-- local c = {}
|
||||||
|
-- c.name = name
|
||||||
|
-- c.Name = name
|
||||||
|
-- c.Id = count
|
||||||
|
-- c.loadString = {"base","package","os","io","math","table","string","coroutine"}
|
||||||
|
-- livingThreads[count] = {true, name}
|
||||||
|
-- c.returns = return_linda
|
||||||
|
-- c.Type = "sthread"
|
||||||
|
-- c.creationTime = os.clock()
|
||||||
|
-- c.alive = true
|
||||||
|
-- c.priority = THREAD.Priority_Normal
|
||||||
|
-- c.thread = lanes.gen("*",func)(...)
|
||||||
|
-- count = count + 1
|
||||||
|
-- function c:kill()
|
||||||
|
-- self.thread:cancel()
|
||||||
|
-- multi.print("Thread: '" .. self.name .. "' has been stopped!")
|
||||||
|
-- self.alive = false
|
||||||
|
-- end
|
||||||
|
-- table.insert(multi.SystemThreads, c)
|
||||||
|
-- c.OnDeath = multi:newConnection()
|
||||||
|
-- c.OnError = multi:newConnection()
|
||||||
|
-- GLOBAL["__THREADS__"] = livingThreads
|
||||||
|
-- return c
|
||||||
|
-- end
|
||||||
|
|
||||||
lanes.gen("*",function()
|
multi:newSystemThread("test",function()
|
||||||
print("Hello!")
|
print("Hello World!")
|
||||||
end)()
|
end)
|
||||||
|
|
||||||
multi:newThread("Test thread",function()
|
multi:newThread("Test thread",function()
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user