From 628371d0edea22eb177fa2b1a6b9f28e8c0cff2d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 28 Aug 2025 23:14:13 +0800 Subject: add thread queue --- tests/modules/thread/queue.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/modules/thread/queue.lua (limited to 'tests/modules/thread/queue.lua') 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 + -- cgit v1.3.1