blob: e969c0747beb139b0e6bf24c257ce8c16776af69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
|