Project

General

Profile

Actions

Bug #6343

closed

Improved Fiber documentation

Added by andhapp (Anuj Dutta) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
1.9.3
Backport:
[ruby-core:44540]

Description

Added an example for Fiber's transfer. Patch Attached.


Files

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Assigned
Actions #2

Updated by ayumin (Ayumu AIZAWA) over 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35519.
Anuj, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Updated by ko1 (Koichi Sasada) over 12 years ago

Hi,

We shouldn't mix Fiber#yield, Fiber.resume and Fiber.transfer. In other
words, fiber1 shouldn't use Fiber#resume on the your example.

I think it is a bug of current Ruby.

--
// SASADA Koichi at atdot dot net

Updated by andhapp (Anuj Dutta) over 12 years ago

Hi,

Thanks ko1 for your comment. The example doesn't use Fiber#resume on fiber1. It uses Fiber.yield to return to the calling context. However, can you please explain how it should work? I mean, why do you think it's a bug?

Thanks.

Updated by ko1 (Koichi Sasada) over 12 years ago

(2012/05/03 8:12), andhapp (Anuj Dutta) wrote:

Thanks ko1 for your comment. The example doesn't use Fiber#resume on fiber1. It uses Fiber.yield to return to the calling context. However, can you please explain how it should work? I mean, why do you think it's a bug?

You shouldn't use Fiber.yield for "transferred" fiber (in this case, f1).

require 'fiber'

f1 = f2 = f3 = nil

f1 = Fiber.new{
p:f1
f2.transfer
p:f2
}

f2 = Fiber.new{
p:f2
Fiber.yield
}

p:a
f1.resume
p:b

In this case, what do you expect?

Output:
ruby 2.0.0dev (2012-05-01 trunk 35505) [i386-mswin32_100]
:a
:f1
:f2
:b

Sequence:
Root f1 f2

p:a
f1.yield
p:f1
f2.transfer
p:f2
Fiber.yield (*1)
p:b

Transferred fiber didn't know which fiber should it return to. So root
fiber was selected. I think it can cause error (FiberError because
transferred fiber should not use "Fiber.yield"). This is why I think
ruby's bug.

The following code cause an error.

require 'fiber'

fr = Fiber.current
f1 = Fiber.new{
fr.transfer
}
f1.resume
Fiber.yield

#=>
ruby 2.0.0dev (2012-05-01 trunk 35505) [i386-mswin32_100]
t.rb:8:in yield': can't yield from root fiber (FiberError) from t.rb:8:in '

Regards,
Koichi

--
// SASADA Koichi at atdot dot net

Updated by andhapp (Anuj Dutta) over 12 years ago

Thanks, ok that makes sense. What should happen if someone does try and yield from a fiber that has been transferred control to from some other fiber? I will add it to RubySpec which is currently missing the spec for Fiber transfer. Thanks.

Anuj

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0