summaryrefslogtreecommitdiff
path: root/test/test_join_detach.lua
blob: 533a36f90a6fb66a0154369dcbc97e8ecd5d60bd (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local llthreads = require"llthreads"
local utils     = require "utils"

do

local thread = llthreads.new(utils.thread_init .. [[
  local sleep = require"utils".sleep
  while true do sleep(1) end
]])

-- detached + joindable
thread:start(true, true)

local ok, err = thread:join(0)
print("thread:join(0): ", ok, err)
assert(ok == nil)
assert(err == "timeout")

end

-- enforce collect `thread` object
-- we should not hungup
for i = 1, 10 do collectgarbage("collect") end


do

local thread = llthreads.new(utils.thread_init .. [[
  local sleep = require"utils".sleep
  sleep(1)
]])

-- detached + joindable
thread:start(true, true)

local ok, err = thread:join(0)
print("thread:join(0): ", ok, err)
assert(ok == nil)
assert(err == "timeout")

for i = 1, 12 do
  utils.sleep(5)
  ok, err = thread:join(0)
  print("thread:join(0)#" .. i .. ": ", ok, err)
  if ok then break end
  assert(err == 'timeout')
end

assert(ok)

end

-- enforce collect `thread` object
-- we should not get av
for i = 1, 10 do collectgarbage("collect") end


print("Done!")