Bug #7678

$_ and $~ are shared across Fibers halfway

Added by Nobuyoshi Nakada over 1 year ago. Updated about 1 year ago.

[ruby-core:51331]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:2.0.0
ruby -v:r38748 Backport:

Description

=begin
((|$_|)) and ((|$~|)) have thread local method scope, but are shared across fibers in same thread.

$ ./ruby -v -e '/a/ =~ "a"; p $~; Fiber.new{/b/=~"b"; p $~}.resume; p $~'
ruby 2.0.0dev (2013-01-09 trunk 38748) [x86_64-darwin11]
#
#
#

But, it is cleared at (({Fiber.start})).

$ ./ruby -v -e '/a/ =~ "a"; p $~; Fiber.new{p $~}.resume; p $~'
ruby 2.0.0dev (2013-01-09 trunk 38748) [x86_64-darwin11]
#
nil
nil

These two behaviors seem mismatched. I think:

  • If they should be shared, then the latter example should show same
    (({MatchData})) 3 times.

  • If they should be cleared at starting fibers, those variables in the
    original fiber should be unchanged.
    =end

Associated revisions

Revision 38981
Added by Nobuyoshi Nakada about 1 year ago

cont.c: fiber local svar

  • cont.c (contrestorethread): svar should be separate per fibers. [Bug #7678]

History

#1 Updated by Koichi Sasada about 1 year ago

  • Target version set to 2.0.0

Nobu, should we finish this issue before 2.0?

#2 Updated by Nobuyoshi Nakada about 1 year ago

  • Description updated (diff)

I think this is one of undefined behaviors, so it would cause no compatibility issue.
We can fix it once we decide which is more desirable, shared between fibers or separate per fibers.

#3 Updated by Koichi Sasada about 1 year ago

(2013/01/29 14:19), nobu (Nobuyoshi Nakada) wrote:

I think this is one of undefined behaviors, so it would cause no compatibility issue.
We can fix it once we decide which is more desirable, shared between fibers or separate per fibers.

I asked matz about it and his choice is separate between Fibers.

--
// SASADA Koichi at atdot dot net

#4 Updated by Nobuyoshi Nakada about 1 year ago

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

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


cont.c: fiber local svar

  • cont.c (contrestorethread): svar should be separate per fibers. [Bug #7678]

Also available in: Atom PDF