aboutsummaryrefslogtreecommitdiff
path: root/llthreads2/test/test_llthreads.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--llthreads2/test/test_llthreads.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/llthreads2/test/test_llthreads.lua b/llthreads2/test/test_llthreads.lua
new file mode 100644
index 0000000..e0e214b
--- /dev/null
+++ b/llthreads2/test/test_llthreads.lua
@@ -0,0 +1,60 @@
1-- Copyright (c) 2011 by Robert G. Jakabosky <bobby@sharedrealm.com>
2--
3-- Permission is hereby granted, free of charge, to any person obtaining a copy
4-- of this software and associated documentation files (the "Software"), to deal
5-- in the Software without restriction, including without limitation the rights
6-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-- copies of the Software, and to permit persons to whom the Software is
8-- furnished to do so, subject to the following conditions:
9--
10-- The above copyright notice and this permission notice shall be included in
11-- all copies or substantial portions of the Software.
12--
13-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-- THE SOFTWARE.
20
21local llthreads = require"llthreads"
22local sleep = require"utils".sleep
23
24print("LLThreads version : ", llthreads._VERSION)
25
26local function detached_thread(...)
27 local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...)
28 -- start detached thread
29 assert(thread:start(true))
30 return thread
31end
32
33local function print_thread(...)
34 local thread = llthreads.new([[ print("print_thread:", ...); ]], ...)
35 -- start joinable thread
36 assert(thread:start())
37 return thread
38end
39
40local function pass_through_thread(...)
41 local thread = llthreads.new([[ return "pass_thread:", ... ]], ...)
42 -- start joinable thread
43 assert(thread:start())
44 return thread
45end
46
47local thread1 = detached_thread("number:", 1234, "nil:", nil, "bool:", true)
48
49sleep(1)
50
51local thread2 = print_thread("number:", 1234, "nil:", nil, "bool:", true)
52print("thread2:join: results # = ", select('#', thread2:join()))
53
54sleep(1)
55
56local thread3 = pass_through_thread("number:", 1234, "nil:", nil, "bool:", true)
57print("thread3:join:", thread3:join())
58
59sleep(1)
60