function receive(prod)
print("receive is called")
local status,value = coroutine.resume(prod)
return value
end
function send(x,prod)
print("send is called")
return coroutine.yield(x)
end
function producer()
return coroutine.create(function ()
print("producer is called")
while true do
print("producer run again")
local x = io.read()
send(x)
end
end)
end
function filter(prod)
return coroutine.create(function ()
for line = 1,1000 do
print("enter fliter "..line)
local x = receive(prod)
print("receive in filter finished")
x= string.format("%5d %s",line,x)
send(x,prod)
end
end)
end
function consumer(prod)
print("consumer is called")
while true do
print("consumer run again")
local x = receive(prod)
print("retrun customer")
io.write(x,"\n")
end
end
p = producer()
f=filter(p)
consumer(f)
consumer is called consumer run again receive is called enter fliter 1 receive is called producer is called producer run again fsy send is called receive in filter finished send is called retrun customer 1 fsy consumer run again receive is called enter fliter 2 receive is called producer run again gaga send is called receive in filter finished send is called retrun customer 2 gaga consumer run again receive is called enter fliter 3 receive is called producer run again ......
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有