Forum: Ruby-core [ruby-trunk - Bug #7678][Open] $_ and $~ are shared across Fibers halfway

Posted by Nobuyoshi Nakada (nobu)
on 2013-01-09 08:59
(Received via mailing list)
Issue #7678 has been reported by nobu (Nobuyoshi Nakada).

----------------------------------------
Bug #7678: $_ and $~ are shared across Fibers halfway
https://bugs.ruby-lang.org/issues/7678

Author: nobu (Nobuyoshi Nakada)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
ruby -v: r38748


$_ 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.
Posted by ko1 (Koichi Sasada) (Guest)
on 2013-01-25 04:43
(Received via mailing list)
Issue #7678 has been updated by ko1 (Koichi Sasada).

Target version set to 2.0.0

Nobu, should we finish this issue before 2.0?
----------------------------------------
Bug #7678: $_ and $~ are shared across Fibers halfway
https://bugs.ruby-lang.org/issues/7678#change-35608

Author: nobu (Nobuyoshi Nakada)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 2.0.0
ruby -v: r38748


$_ 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.
Posted by Nobuyoshi Nakada (nobu)
on 2013-01-29 06:19
(Received via mailing list)
Issue #7678 has been updated by nobu (Nobuyoshi Nakada).

Description updated

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.

----------------------------------------
Bug #7678: $_ and $~ are shared across Fibers halfway
https://bugs.ruby-lang.org/issues/7678#change-35697

Author: nobu (Nobuyoshi Nakada)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 2.0.0
ruby -v: r38748


=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
Posted by SASADA Koichi (Guest)
on 2013-01-29 06:37
(Received via mailing list)
(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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.