Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock? #17

Closed
jesseshieh opened this issue Jun 13, 2014 · 1 comment
Closed

Deadlock? #17

jesseshieh opened this issue Jun 13, 2014 · 1 comment

Comments

@jesseshieh
Copy link

Hi, I'm not sure if I'm doing this wrong, but the following code prints waiting forever and never exits. I'm guessing there is a deadlock somewhere, but I'm not sure.

require 'agent'

channel = channel!(Integer)

def read_channel
  channel.receive
end

go! do
  puts read_channel
  channel.close
end

go! do
  channel.send(1)
end

while not channel.closed? do
  sleep 0.1
  puts 'waiting'
end

puts 'done'

If I replace the function with a lambda instead, then it works fine, done is printed and the program exits. Do you know why this might be happening? Thank you for making this gem!

require 'agent'

channel = channel!(Integer)

read_channel = lambda do
  channel.receive
end

go! do
  puts read_channel.call
  channel.close
end

go! do
  channel.send(1)
end

while not channel.closed? do
  sleep 0.1
  puts 'waiting'
end

puts 'done'
@jesseshieh
Copy link
Author

By the way, I'm running on
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-darwin13.1.0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant