summaryrefslogtreecommitdiff
path: root/tests/modules/thread/semaphore.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-02 10:16:24 +0800
committerGitHub <[email protected]>2025-09-02 10:16:24 +0800
commit148501afafa5e9e05da7a54bc804880d6c415849 (patch)
treef5cbcee2b05d4b836478a45698c8a42b43ea38b7 /tests/modules/thread/semaphore.lua
parent90b7015682c5523dfa252ebfbab6ed16b3e4b16a (diff)
parent37a499eeb5fd84be4ac83d639211e18e55dccd32 (diff)
Merge pull request #6324 from xmake-io/thread
Add native thread support
Diffstat (limited to 'tests/modules/thread/semaphore.lua')
-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
+