summaryrefslogtreecommitdiff
path: root/tests/modules/thread
diff options
context:
space:
mode:
authorruki <[email protected]>2025-08-29 22:26:32 +0800
committerruki <[email protected]>2025-08-29 22:26:32 +0800
commit1018ca3221d60d8190ffa09f69b31fc88c7f192d (patch)
tree142c310a0e424fe4d046f328fdf5e61c9aa11085 /tests/modules/thread
parent3a1890f777eec156fd4e85616e9487a4fdc92abc (diff)
add thread/coroutine tests
Diffstat (limited to 'tests/modules/thread')
-rw-r--r--tests/modules/thread/coroutine.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/modules/thread/coroutine.lua b/tests/modules/thread/coroutine.lua
new file mode 100644
index 000000000..28aa8971e
--- /dev/null
+++ b/tests/modules/thread/coroutine.lua
@@ -0,0 +1,32 @@
+import("core.base.thread")
+import("core.base.scheduler")
+
+function thread_loop()
+ import("core.base.thread")
+ print("%s: starting ..", thread.running())
+ local dt = os.mclock()
+ for i = 1, 10 do
+ print("%s: %d", thread.running(), i)
+ os.sleep(1000)
+ end
+ dt = os.mclock() - dt
+ print("%s: end, dt: %d ms", thread.running(), dt)
+end
+
+function coroutine_loop()
+ print("%s: starting ..", scheduler.co_running())
+ local dt = os.mclock()
+ for i = 1, 10 do
+ print("%s: %d", scheduler.co_running(), i)
+ os.sleep(1000)
+ end
+ dt = os.mclock() - dt
+ print("%s: end, dt: %d ms", scheduler.co_running(), dt)
+end
+
+function main()
+ scheduler.co_start_named("coroutine", coroutine_loop)
+ local t = thread.start_named("thread", thread_loop)
+ t:wait(-1)
+end
+