local producer = coroutine.create(function()
for i=1,3 do
print("生产:", i)
coroutine.yield(i) -- 暂停,返回 i
end
end)
-- 消费者
while true do
local ok, val = coroutine.resume(producer)
if not ok or coroutine.status(producer)=="dead" then break end
print("消费:", val)
end