-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample05.lua
More file actions
27 lines (27 loc) · 1.16 KB
/
example05.lua
File metadata and controls
27 lines (27 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local llthreads = require("llthreads2.ex")
local mtmsg = require("mtmsg")
local threadIn = mtmsg.newbuffer()
local lst = mtmsg.newlistener()
local threadOut = lst:newbuffer()
local thread = llthreads.new(function(inId, outId)
local mtmsg = require("mtmsg")
local threadIn = mtmsg.buffer(inId)
local threadOut = mtmsg.buffer(outId)
threadOut:addmsg("started")
assert(threadIn:nextmsg() == "exit")
threadOut:addmsg("finished")
end,
threadIn:id(),
threadOut:id())
-- threadOut = nil -- not now!
-- collectgarbage()
thread:start()
assert(lst:nextmsg() == "started")
threadOut = nil -- now it's safe
collectgarbage()
threadIn:addmsg("exit")
assert(lst:nextmsg() == "finished")
assert(thread:join())
collectgarbage()
local _, err = pcall(function() lst:nextmsg() end)
assert(err:match(mtmsg.error.no_buffers))