title: Simple parallelism with Fibers?
body: <p>I'm trying to validate a basic yield/resume pattern with two Fibers. However, the yield/resume mechanism doesn't seem to work. I have tried a few variations but can't find my mistake.</p>
  
  <p>Expected sequence of events:</p>
  
  <ol>
  <li>kick off threads (time 0)</li>
  <li>wait until first returns (time +2sec)</li>
  <li>wait until 2nd returns (time +2sec)</li>
  <li>done (time > +3sec)</li>
  </ol>
  
  <p><strong>Try #1</strong></p>
  
  <pre><code>#!/usr/bin/env ruby
  
  require 'fiber'
  
  f1 = Fiber.new do
      puts "Fiber1 starting @ #{Time.new}."
      fib1 = Fiber.current
      Fiber.yield
      sleep 2
      puts "Fiber1 done @ #{Time.new}."
      fib1.resume(1)
  end
  f2 = Fiber.new do
      puts "Fiber2 starting @ #{Time.new}."
      fib2 = Fiber.current
      Fiber.yield
      sleep 2
      puts "Fiber2 done @ #{Time.new}."
      fib2.resume(2)
  end
  
  puts "Waiting @ #{Time.new}."
  r1 = f1.resume
  puts "f1 back @ #{Time.new} - #{r1}."
  r2 = f2.resume
  puts "f2 back @ #{Time.new} - #{r2}."
  
  sleep 1
  puts "Done @ #{Time.now}."
  </code></pre>
  
  <p>This results in:</p>
  
  <pre><code>Waiting @ 2016-06-01 06:15:52 -0700.
  Fiber1 starting @ 2016-06-01 06:15:52 -0700.
  f1 back @ 2016-06-01 06:15:52 -0700 - .
  Fiber2 starting @ 2016-06-01 06:15:52 -0700.
  f2 back @ 2016-06-01 06:15:52 -0700 - .
  Done @ 2016-06-01 06:15:53 -0700.
  </code></pre>
  
  <p>Adding a second <code>resume</code> results in a FiberError. </p>
  
  <p><strong>Try #2</strong></p>
  
  <pre><code>#!/usr/bin/env ruby
  
  require 'fiber'
  
  f1 = Fiber.new do
      puts "Fiber1 starting @ #{Time.new}."
      Fiber.yield
      sleep 2
      puts "Fiber1 done @ #{Time.new}."
      1
  end
  f2 = Fiber.new do
      puts "Fiber2 starting @ #{Time.new}."
      Fiber.yield
      sleep 2
      puts "Fiber2 done @ #{Time.new}."
      2
  end
  
  puts "Waiting @ #{Time.new}."
  r1 = f1.resume
  puts "f1 back @ #{Time.new} - #{r1}."
  r2 = f2.resume
  puts "f2 back @ #{Time.new} - #{r2}."
  
  sleep 1
  puts "Done @ #{Time.now}."
  </code></pre>
  
  <p>This results in:</p>
  
  <pre><code>Waiting @ 2016-06-01 10:53:17 -0700.
  Fiber1 starting @ 2016-06-01 10:53:17 -0700.
  f1 back @ 2016-06-01 10:53:17 -0700 - .
  Fiber2 starting @ 2016-06-01 10:53:17 -0700.
  f2 back @ 2016-06-01 10:53:17 -0700 - .
  Done @ 2016-06-01 10:53:18 -0700.
  </code></pre>
  
  <p>In both cases, the start/end time is the same and result not returned.</p>