Skip to content

Instantly share code, notes, and snippets.

@halorgium
Created April 13, 2013 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halorgium/f63abf177a96d7113ce3 to your computer and use it in GitHub Desktop.
Save halorgium/f63abf177a96d7113ce3 to your computer and use it in GitHub Desktop.
require 'thread'
input = Queue.new
output = Queue.new
thread = Thread.new {
one = Fiber.new {
loop {
p(running: :one)
output << :one
sleep 2
Fiber.yield
}
}.resume
two = Fiber.new {
loop {
p(running: :two)
output << :two
sleep 2
Fiber.yield
}
}.resume
while fiber = input.pop
{one: one, two: two}.resume
end
}
input << :one
output.pop
puts "backtrace running one"
puts thread.backtrace
input << :two
output.pop
puts "backtrace running two"
puts thread.backtrace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment