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
|
local llthreads = require"llthreads"
local utils = require "utils"
local sleep = utils.sleep
local include = utils.thread_init .. [[
local llthreads = require"llthreads"
local sleep = require "utils".sleep
]]
do
local thread = llthreads.new(include .. [[
for i = 1, 10 do sleep(1) end
]])
thread:start()
sleep(1)
thread:interrupt()
local ok, err = thread:join()
print("thread1:join(): ", ok, err)
assert(ok == false and err:match(llthreads.interrupted_error), "thread1 result")
print("--- Done interrupt1!")
end
do
local thread = llthreads.new(include .. [[
local ok, err = pcall(function() for i = 1, 10 do sleep(1) end end)
print("thread2:", ok, err)
assert(ok == false and err:match(llthreads.interrupted_error), "interrupt2 result")
]])
thread:start()
sleep(1)
thread:interrupt()
local ok, err = thread:join()
print("thread2:join(): ", ok, err)
assert(ok, "thread2 result")
print("--- Done interrupt2!")
end
do
local thread = llthreads.new(include .. [[
local ok, err = pcall(function() for i = 1, 10 do sleep(1) end end)
print("thread3:", ok, err)
]])
thread:start()
sleep(1)
thread:interrupt(true)
local ok, err = thread:join()
print("thread3:join(): ", ok, err)
assert(ok == false and err:match(llthreads.interrupted_error), "thread3 result")
print("--- Done interrupt3!")
end
|