aboutsummaryrefslogtreecommitdiff
path: root/test/test_join_detach.lua
blob: 329fb27bf5c20d8ee5f8187d9f56cd9647486d96 (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
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")

utils.sleep(5)
local ok, err = thread:join(0)
print("thread:join(0): ", ok, err)
assert(ok)

end

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


print("Done!")