Project

General

Profile

Actions

Bug #7678

closed

$_ and $~ are shared across Fibers halfway

Added by nobu (Nobuyoshi Nakada) over 11 years ago. Updated about 11 years ago.

Status:
Closed
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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0