diff options
| author | ruki <[email protected]> | 2025-09-02 10:16:24 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-02 10:16:24 +0800 |
| commit | 148501afafa5e9e05da7a54bc804880d6c415849 (patch) | |
| tree | f5cbcee2b05d4b836478a45698c8a42b43ea38b7 /tests/modules/thread/mutex.lua | |
| parent | 90b7015682c5523dfa252ebfbab6ed16b3e4b16a (diff) | |
| parent | 37a499eeb5fd84be4ac83d639211e18e55dccd32 (diff) | |
Merge pull request #6324 from xmake-io/thread
Add native thread support
Diffstat (limited to 'tests/modules/thread/mutex.lua')
| -rw-r--r-- | tests/modules/thread/mutex.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/modules/thread/mutex.lua b/tests/modules/thread/mutex.lua new file mode 100644 index 000000000..e969c0747 --- /dev/null +++ b/tests/modules/thread/mutex.lua @@ -0,0 +1,24 @@ +import("core.base.thread") + +function callback(mutex) + import("core.base.thread") + print("%s: starting ..", thread.running()) + local dt = os.mclock() + for i = 1, 10 do + mutex:lock() + print("%s: %d", thread.running(), i) + mutex:unlock() + os.sleep(1000) + end + dt = os.mclock() - dt + print("%s: end, dt: %d ms", thread.running(), dt) +end + +function main() + local mutex = thread.mutex() + local t0 = thread.start_named("thread_0", callback, mutex) + local t1 = thread.start_named("thread_1", callback, mutex) + t0:wait(-1) + t1:wait(-1) +end + |
