summaryrefslogtreecommitdiff
path: root/tests/modules/thread/mutex.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-08-26 22:51:55 +0800
committerruki <[email protected]>2025-08-28 11:35:53 +0800
commit6a01597d31c28c6a55c00678ddbf9c9929a09468 (patch)
tree1843efed352e615976367cd37b069b0df7e65805 /tests/modules/thread/mutex.lua
parent12b67495cd7114b10a1139a3ea81a45e402e7aba (diff)
add mutex test
Diffstat (limited to 'tests/modules/thread/mutex.lua')
-rw-r--r--tests/modules/thread/mutex.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/modules/thread/mutex.lua b/tests/modules/thread/mutex.lua
new file mode 100644
index 000000000..472b228db
--- /dev/null
+++ b/tests/modules/thread/mutex.lua
@@ -0,0 +1,25 @@
+import("core.thread.thread")
+import("core.thread.mutex")
+
+function callback(mutex)
+ import("core.thread.thread")
+ print("%s: starting ..", thread.running())
+ local dt = os.mclock()
+ for i = 1, 10 do
+ mutex:lock()
+ print("%s: %d", thread.running(), i)
+ os.sleep(1000)
+ mutex:unlock()
+ end
+ dt = os.mclock() - dt
+ print("%s: end, dt: %d ms", thread.running(), dt)
+end
+
+function main()
+ local m = mutex.new()
+ local t0 = thread.start_named("thread_0", callback, m)
+ local t1 = thread.start_named("thread_1", callback, m)
+ t0:wait(-1)
+ t1:wait(-1)
+end
+