diff options
Diffstat (limited to '')
| -rw-r--r-- | llthreads2/test/test_alive.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llthreads2/test/test_alive.lua b/llthreads2/test/test_alive.lua new file mode 100644 index 0000000..ecce163 --- /dev/null +++ b/llthreads2/test/test_alive.lua | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | local llthreads = require"llthreads" | ||
| 2 | local utils = require "utils" | ||
| 3 | local sleep = utils.sleep | ||
| 4 | |||
| 5 | local include = utils.thread_init .. [[ | ||
| 6 | local llthreads = require"llthreads" | ||
| 7 | local sleep = require "utils".sleep | ||
| 8 | ]] | ||
| 9 | |||
| 10 | local thread = llthreads.new(include .. [[ | ||
| 11 | sleep(5) | ||
| 12 | return 1,2,3 | ||
| 13 | ]]) | ||
| 14 | |||
| 15 | assert(nil == thread:alive()) | ||
| 16 | |||
| 17 | thread:start() | ||
| 18 | |||
| 19 | assert(true == thread:alive()) | ||
| 20 | |||
| 21 | for i = 1, 10 do | ||
| 22 | if not thread:alive() then break end | ||
| 23 | sleep(1) | ||
| 24 | end | ||
| 25 | |||
| 26 | assert(false == thread:alive()) | ||
| 27 | |||
| 28 | local ok,a,b,c = thread:join(0) | ||
| 29 | assert(ok == true) | ||
| 30 | assert(a == 1) | ||
| 31 | assert(b == 2) | ||
| 32 | assert(c == 3) | ||
| 33 | |||
| 34 | print("Done!") | ||
| 35 | |||
