Skip to content

Commit

Permalink
Modify ping-pong example for reproducing #4 (a starvation issue).
Browse files Browse the repository at this point in the history
Signed-off-by: Xiongfei(Alex) Guo <[email protected]>
  • Loading branch information
Xiongfei(Alex) Guo committed Aug 4, 2014
1 parent c068bab commit d8756bd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions example/pingpong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,42 @@ local reactor_name = os.getenv("LUACTOR_REACTOR") or 'luaevent'
print('The reactor you use is *'..reactor_name..'*.')

local ping = function ()
-- ping-pong for 1 second
actor.register_event(
'timeout', -- event type
'stop', -- event name
1 -- event parameters
)
print("ping start")
for _ = 1,100 do
local finish = false
while not finish do
actor.wait({
bar = function (msg, sender)
print(string.format('msg from:%s msg:%s', sender, msg))
actor.send("pong", "foo", "hello")
end,
timeout = function (msg, sender)
actor.send("pong", "exit")
finish = true
print("End")
end
})
end
end

local pong = function ()
print("pong start")
for _ = 1,100 do
local finish = false
while not finish do
actor.wait({
foo = function (msg, sender)
print(string.format('msg from:%s msg:%s', sender, msg))
actor.send("ping", "bar", "world")
end,
timeout = function (msg, sender)
finish = true
print("End Received")
end
})
end
end
Expand Down

0 comments on commit d8756bd

Please sign in to comment.