summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2025-08-28 22:45:48 +0800
committerruki <[email protected]>2025-08-28 11:35:54 +0800
commit8a331ab64fe560924b8bc3ab3dc4ac2831dd8920 (patch)
tree1b7406be4f6db49c198d36d180b4f98ff8185847 /tests/modules
parenta3ff692d028873e06cc9827e1ff72dc9ec8b54d4 (diff)
add thread semaphore
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/thread/semaphore.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/modules/thread/semaphore.lua b/tests/modules/thread/semaphore.lua
new file mode 100644
index 000000000..b05774e1d
--- /dev/null
+++ b/tests/modules/thread/semaphore.lua
@@ -0,0 +1,25 @@
+import("core.base.thread")
+
+function callback(semaphore)
+ import("core.base.thread")
+ print("%s: starting ..", thread.running())
+ while true do
+ print("%s: waiting ..", thread.running())
+ if semaphore:wait(-1) > 0 then
+ print("%s: triggered", thread.running())
+ end
+ end
+end
+
+function main()
+ local semaphore = thread.semaphore("", 1)
+ local t = thread.start_named("keyboard", callback, semaphore)
+ while true do
+ local ch = io.read()
+ if ch then
+ semaphore:post(2)
+ end
+ end
+ t:wait(-1)
+end
+