[前][次][番号順一覧][スレッド一覧][生データ]

yarv-dev:844

From: sheepman <sheepman sheepman.sakura.ne.jp>
Date: Sun, 12 Feb 2006 15:13:22 +0900
Subject: [yarv-dev:844] Re: open> $& and other variables in proc are not thread local

こんにちは、sheepman です。

On Sat, 11 Feb 2006 11:08:28 +0900
SASADA Koichi <ko1 atdot.net> wrote:

>  うーん、この辺はどっちでもいいような気がしますが、なんかこうじゃないと
> 困るってことはありますかね。

僕もどちらでもいい気がします。とはいえ、個人的には $~, $&, $1 などの
組み込み変数がスレッドローカルであるメリットをあまり良く分かっていないので
意見として参考にならないかも。スレッドローカルではなくても、
ローカルスコープでさえあれば十分だと思ったりするんですが。

ちなみに、以下のようなコードは ruby-1.8 と ruby-1.9 と yarv では
それぞれ結果が違います。スレッドローカルの定義も良く分からない。
どれが仕様として意図された動作なんだろう?

$ cat t.rb
def m_using_thread
  Thread.new{
    yield
  }.join
end

/(.)/ =~ "a"
m_using_thread(){
  p $1
}

class A
  /(.)/ =~ "b"
  m_using_thread(){
    p $1
  }
end

/(.)/ =~ "c"
b = Thread.new{
  proc do
     p $1
  end
}.value
b.call

$ ruby-1.8 -v t.rb
ruby 1.8.4 (2006-02-12) [i686-linux]
"a"
"b"
nil

$ ruby-1.9 -v t.rb
ruby 1.9.0 (2006-02-09) [i686-linux]
nil
"b"
nil

$ ./miniruby -v t.rb
ruby 1.9.0 (2006-02-09) [i686-linux]
YARVCore 0.3.3 (rev: 382) [opts: ]
"a"
"b"
"c"

-- 
sheepman / TAMURA Takashi
sheepman sheepman.sakura.ne.jp http://sheepman.parfait.ne.jp/

-- 
ML: yarv-dev quickml.atdot.net
使い方: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]

       830 2006-02-09 09:20 [sheepman sheepman.sa] open> $& and other variables are not thread local
       832 2006-02-10 08:47 ┗[ko1 atdot.net       ] fixed> Re: open> $& and other variables are not thread local
       835 2006-02-11 10:48  ┗[sheepman sheepman.sa] open> $& and other variables in proc are not thread local
       836 2006-02-11 11:08   ┗[ko1 atdot.net       ]                                   
->     844 2006-02-12 15:13    ┗[sheepman sheepman.sa]