Project

General

Profile

Feature #13821 ยป fiber_across_threads.rb

reproduction code - cremes (Chuck Remes), 08/16/2017 05:01 PM

 
1
queue = Queue.new
2

    
3
threadA = Thread.new do
4
  fiber = Fiber.new do
5
    puts "Created in ThreadA"
6
    val = Fiber.yield
7
    puts "Resumed in ThreadB with val #{val}"
8
  end
9
  fiber.resume
10
  queue << fiber
11
end
12

    
13
threadB = Thread.new do
14
  fiber = queue.pop
15
  fiber.resume(3)
16
end
17

    
18
threadA.join
19
threadB.join
20

    
21
# Expect this output:
22
# Created in ThreadA
23
# Resumed in ThreadB with val 3
24