まつもと ゆきひろです.

In message "[ruby-list:1273] Re: thread and $1"
    on 96/12/12, 石塚圭樹 <keiju / shljapan.co.jp> writes:
|
|けいじゅ@SHLジャパンです. 
|
|In [ruby-list :01272 ] the message: "[ruby-list:1272] Re: thread and
|$1 ", on Dec/12 16:09(JST) matz / caelum.co.jp (Yukihiro Matsumoto)
|writes:
|
|>以下のものはグローバル変数のようにみえますが,実はローカル変
|>数です(マニュアルにも書いてあります).
|>
|>  $_ $~ $& $` $' $+ $1 $2 ...

|ん? そうすると以下のプログラムの動作は, おかしくないのですか??

おかしいですね.$_, $~はローカル変数であるだけではなくてスレッ
ドローカルにもしないといけなかったんですね.修正します.

|こういう動作は困り物だと思うのですが??

全くです.ローカル変数だから大丈夫だと思い込んでいましたが,
そういえばローカル変数ってthread間で共有されるんですよね.

|もう1つ:

|Thread.exit
|
|するとコアダンプします.

main threadでThread.exitするとcore dumpしていました.

パッチです.

--- eval.c~	Thu Dec 12 00:22:50 1996
+++ eval.c	Thu Dec 12 16:47:00 1996
@@ -3668,2 +3668,4 @@
     VALUE last_status;
+    VALUE last_line;
+    VALUE last_match;
 
@@ -3769,2 +3771,7 @@
 
+VALUE lastline_get();
+void lastline_set();
+VALUE backref_get();
+void backref_set();
+
 static int
@@ -3795,2 +3802,5 @@
     th->last_status = last_status;
+    th->last_line = lastline_get();
+    th->last_match = backref_get();
+
     th->file = sourcefile;
@@ -3843,2 +3853,6 @@
     last_status = th->last_status;
+
+    lastline_set(th->last_line);
+    backref_set(th->last_match);
+
     sourcefile = th->file;
@@ -4263,3 +4277,3 @@
     if (th->status == THREAD_KILLED) return Qnil; 
-    if (th == th->next) rb_exit(0);
+    if (th == th->next || th == main_thread) rb_exit(0);