Project

General

Profile

Actions

Bug #7678

closed

$_ and $~ are shared across Fibers halfway

Added by nobu (Nobuyoshi Nakada) almost 10 years ago. Updated almost 10 years ago.

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

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]
#<MatchData "a">
#<MatchData "b">
#<MatchData "b">

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]
#<MatchData "a">
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

Actions #1

Updated by ko1 (Koichi Sasada) almost 10 years ago

  • Target version set to 2.0.0

Nobu, should we finish this issue before 2.0?

Updated by nobu (Nobuyoshi Nakada) almost 10 years 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.

Updated by ko1 (Koichi Sasada) almost 10 years 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

Actions #4

Updated by nobu (Nobuyoshi Nakada) almost 10 years 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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0