diff options
| author | ruki <[email protected]> | 2025-08-28 23:14:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-08-28 23:14:13 +0800 |
| commit | 628371d0edea22eb177fa2b1a6b9f28e8c0cff2d (patch) | |
| tree | 2c8e834e76870f3cfa2e2b2b3b3342d69b0f83bf /tests/modules/thread | |
| parent | 8a331ab64fe560924b8bc3ab3dc4ac2831dd8920 (diff) | |
add thread queue
Diffstat (limited to 'tests/modules/thread')
| -rw-r--r-- | tests/modules/thread/queue.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/modules/thread/queue.lua b/tests/modules/thread/queue.lua new file mode 100644 index 000000000..36034993f --- /dev/null +++ b/tests/modules/thread/queue.lua @@ -0,0 +1,30 @@ +import("core.base.thread") + +function callback(event, queue) + import("core.base.thread") + print("%s: starting ..", thread.running()) + while true do + print("%s: waiting ..", thread.running()) + if event:wait(-1) > 0 then + print("%s: triggered", thread.running()) + end + while not queue:empty() do + print("%s: get %s", thread.running(), queue:pop()) + end + end +end + +function main() + local event = thread.event() + local queue = thread.queue() + local t = thread.start_named("keyboard", callback, event, queue) + while true do + local ch = io.read() + if ch then + queue:push(ch) + event:post() + end + end + t:wait(-1) +end + |
