Bug #6343

Improved Fiber documentation

Added by Anuj Dutta almost 2 years ago. Updated almost 2 years ago.

[ruby-core:44540]
Status:Closed
Priority:Normal
Assignee:Eric Hodel
Category:doc
Target version:-
ruby -v:1.9.3 Backport:

Description

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

Added-documentation-for-fiber-transfer.patch Magnifier (1.15 KB) Anuj Dutta, 04/23/2012 02:40 PM

Associated revisions

Revision 35519
Added by Ayumu AIZAWA almost 2 years ago

  • cont.c: Improved Fiber documentation.[Bug #6343]

History

#1 Updated by Yusuke Endoh almost 2 years ago

  • Status changed from Open to Assigned

#2 Updated by Ayumu AIZAWA almost 2 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.


  • cont.c: Improved Fiber documentation.[Bug #6343]

#3 Updated by Koichi Sasada almost 2 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

#4 Updated by Anuj Dutta almost 2 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.

#5 Updated by Koichi Sasada almost 2 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

#6 Updated by Anuj Dutta almost 2 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

Also available in: Atom PDF