blob: b05774e1da82a9b6fc0ecaeacc885b9224d9399d (
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
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
|