[#20525] [BigDecimal] changing rule of coerce — "Tadashi Saito" <shiba@...2.accsnet.ne.jp>

斎藤です。

44 messages 2003/07/07
[#20527] Re: [BigDecimal] changing rule of coerce — "Shigeo Kobayashi" <shigeo@...> 2003/07/07

小林です。

[#20528] Re: [BigDecimal] changing rule of coerce — matz@... (Yukihiro Matsumoto) 2003/07/07

まつもと ゆきひろです

[#20570] Marshal upgrade — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

41 messages 2003/07/09
[#20575] Re: Marshal upgrade — Masatoshi SEKI <m_seki@...> 2003/07/09

咳といいます。

[#20583] Re: Marshal upgrade — matz@... (Yukihiro Matsumoto) 2003/07/09

まつもと ゆきひろです

[#21016] Re: Marshal upgrade — matz@... (Yukihiro Matsumoto) 2003/07/30

まつもと ゆきひろです

[#20804] add library — nobu.nakada@... 2003/07/23

なかだです。

[#20580] add library(Re:ruby-dev:20570) — たむらけんいち <sgs02516@...>

たむらです。

30 messages 2003/07/09
[#20656] Re: add library — "NAKAMURA, Hiroshi" <nakahiro@...> 2003/07/14

なひです。

[#20658] Re: add library — GOTOU Yuuzou <gotoyuzo@...> 2003/07/14

In message <038d01c349cb$eaad71d0$93222fc0@sarion.co.jp>,

[#20659] Re: add library — matz@... (Yukihiro Matsumoto) 2003/07/14

まつもと ゆきひろです

[#20660] Re: add library — GOTOU Yuuzou <gotoyuzo@...> 2003/07/14

In message <1058171960.400840.10041.nullmailer@picachu.netlab.jp>,

[#20661] Re: add library — Takahiro Kambe <taca@...> 2003/07/14

話をそらしてしまうかもしれませんが、

[#20665] Re: add library — GOTOU Yuuzou <gotoyuzo@...> 2003/07/14

In message <20030714.183104.09092354.taca@back-street.net>,

[#20666] Re: add library — Takahiro Kambe <taca@...> 2003/07/14

In message <20030715.013655.424936247.gotoyuzo@kotetsu.does.notwork.org>

[#20668] Re: add library — GOTOU Yuuzou <gotoyuzo@...> 2003/07/14

In message <20030715.025907.26217115.taca@back-street.net>,

[#20750] Re: add library — Takahiro Kambe <taca@...> 2003/07/21

In message <20030715.051853.968499478.gotoyuzo@kotetsu.does.notwork.org>

[#20751] Re: add library — GOTOU Yuuzou <gotoyuzo@...> 2003/07/21

In message <20030721.163444.09092937.taca@back-street.net>,

[#20655] frozen ThreadGroup — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

26 messages 2003/07/14
[#20671] Re: frozen ThreadGroup — matz@... (Yukihiro Matsumoto) 2003/07/14

まつもと ゆきひろです

[#20673] Re: frozen ThreadGroup — Hidetoshi NAGAI <nagai@...> 2003/07/15

永井@知能.九工大です.

[#20676] Re: frozen ThreadGroup — matz@... (Yukihiro Matsumoto) 2003/07/15

まつもと ゆきひろです

[#20677] Re: frozen ThreadGroup — Hidetoshi NAGAI <nagai@...> 2003/07/15

永井@知能.九工大です.

[#20681] Re: frozen ThreadGroup — matz@... (Yukihiro Matsumoto) 2003/07/15

まつもと ゆきひろです

[#20690] portable(?) UserID/GroupID control (Re: frozen ThreadGroup) — Hidetoshi NAGAI <nagai@...> 2003/07/16

永井@知能.九工大です.

[#20712] Re: portable(?) UserID/GroupID control — Hidetoshi NAGAI <nagai@...> 2003/07/17

永井@知能.九工大です.

[#20735] Re: portable(?) UserID/GroupID control — matz@... (Yukihiro Matsumoto) 2003/07/20

まつもと ゆきひろです

[#20736] Re: portable(?) UserID/GroupID control — Hidetoshi NAGAI <nagai@...> 2003/07/20

永井@知能.九工大です.

[#20737] Re: portable(?) UserID/GroupID control — matz@... (Yukihiro Matsumoto) 2003/07/20

まつもと ゆきひろです

[#20748] [BigDecimal] exception handling — "Tadashi Saito" <shiba@...2.accsnet.ne.jp>

斎藤です。

20 messages 2003/07/21

[#20765] Re: [ruby-cvs] ruby/lib: * lib/tmpdir.rb: new library to get temporary directory path, — WATANABE Hirofumi <eban@...>

わたなべです。

9 messages 2003/07/21

[#20780] complex.rb — Masahiro TANAKA <masa@...>

complex.rb についての修正案を[ruby-math:00543]で提案しましたが、その後

25 messages 2003/07/22
[#20782] Re: complex.rb — matz@... (Yukihiro Matsumoto) 2003/07/22

まつもと ゆきひろです

[#20900] Re: complex.rb — Masahiro TANAKA <masa@...> 2003/07/25

At Tue, 22 Jul 2003 17:30:31 +0900, Yukihiro Matsumoto wrote:

[#20905] Re: complex.rb — matz@... (Yukihiro Matsumoto) 2003/07/25

まつもと ゆきひろです

[#20906] Re: complex.rb — keiju@... (石塚圭樹) 2003/07/25

けいじゅ@いしつかです.

[#20810] Rational 始めました。 — Shin-ichiro HARA <sinara@...>

原です。

13 messages 2003/07/23
[#20876] Re: Rational 始めました。 — keiju@... (石塚圭樹) 2003/07/24

けいじゅ@いしつかです.

[#20954] ruby 1.8.0 preview5 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

15 messages 2003/07/28

[#20957] [BigDecimal] conflict between Numeric#div and BigDecimal#div — "Tadashi Saito" <shiba@...2.accsnet.ne.jp>

斎藤です。

29 messages 2003/07/28
[#20960] Re: [BigDecimal] conflict between Numeric#div and BigDecimal#div — Masahiro TANAKA <masa@...> 2003/07/28

At Mon, 28 Jul 2003 18:26:20 +0900, Tadashi Saito wrote:

[#20962] Re: [BigDecimal] conflict between Numeric#div and BigDecimal#div — matz@... (Yukihiro Matsumoto) 2003/07/28

まつもと ゆきひろです

[#20990] Re: [BigDecimal] conflict between Numeric#div and BigDecimal#div — Masahiro TANAKA <masa@...> 2003/07/29

At Mon, 28 Jul 2003 21:16:08 +0900, Yukihiro Matsumoto wrote:

[#20992] Re: [BigDecimal] conflict between Numeric#div and BigDecimal#div — matz@... (Yukihiro Matsumoto) 2003/07/29

まつもと ゆきひろです

[ruby-dev:20818] ThreadGroup#wait

From: nobu.nakada@...
Date: 2003-07-23 07:09:43 UTC
List: ruby-dev #20818
なかだです。

# 時期的に微妙ですが。

ThreadGroupの使い途があまりないなと思っていたんですが、thgroup
が追加されたのを機会に、ThreadGroup#waitというのを作ってみまし
た。


Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.491
diff -u -2 -p -r1.491 eval.c
--- eval.c	22 Jul 2003 08:42:44 -0000	1.491
+++ eval.c	23 Jul 2003 07:01:00 -0000
@@ -8335,12 +8442,17 @@ rb_thread_ready(th)
 }
 
+static void thgroup_notify _((VALUE, rb_thread_t));
+
 static void
 rb_thread_die(th)
     rb_thread_t th;
 {
+    VALUE thg = th->thgroup;
+
     th->thgroup = 0;
     th->status = THREAD_KILLED;
     if (th->stk_ptr) free(th->stk_ptr);
     th->stk_ptr = 0;
+    thgroup_notify(thg, th);
 }
 
@@ -8352,7 +8464,7 @@ rb_thread_remove(th)
 
     rb_thread_ready(th);
-    rb_thread_die(th);
     th->prev->next = th->next;
     th->next->prev = th->prev;
+    rb_thread_die(th);
 }
 
@@ -9025,5 +9137,4 @@ rb_thread_kill(thread)
 
     rb_thread_ready(th);
-    th->thgroup = 0;
     th->status = THREAD_TO_KILL;
     if (!rb_thread_critical) rb_thread_schedule();
@@ -9180,4 +9291,18 @@ rb_thread_abort_exc_set(thread, val)
 }
 
+VALUE
+rb_thread_group(thread)
+    VALUE thread;
+{
+    rb_thread_t th = rb_thread_check(thread);
+    return th->thgroup;
+}
+
+struct thgroup {
+    int enclosed, count;
+    VALUE group;
+    VALUE waiting;
+};
+
 #define THREAD_ALLOC(th) do {\
     th = ALLOC(struct thread);\
@@ -9218,4 +9343,6 @@ rb_thread_abort_exc_set(thread, val)
     th->thgroup = thgroup_default;\
     th->locals = 0;\
+\
+    ((struct thgroup *)DATA_PTR(th->thgroup))->count++;\
 } while (0)
 
@@ -9334,5 +9461,7 @@ rb_thread_start_0(fn, arg, th_arg)
 	curr_thread->next = th;
 	th->priority = curr_thread->priority;
+	((struct thgroup *)DATA_PTR(th->thgroup))->count--;
 	th->thgroup = curr_thread->thgroup;
+	((struct thgroup *)DATA_PTR(th->thgroup))->count++;
     }
 
@@ -9547,5 +9676,4 @@ rb_thread_cleanup()
 	if (th->status != THREAD_KILLED) {
 	    rb_thread_ready(th);
-	    th->thgroup = 0;
 	    th->priority = 0;
 	    if (th != main_thread) {
@@ -9882,8 +10010,10 @@ rb_cont_call(argc, argv, cont)
 }
 
-struct thgroup {
-    int enclosed;
-    VALUE group;
-};
+static void
+thgroup_mark(ptr)
+    struct thgroup *ptr;
+{
+    rb_gc_mark(ptr->waiting);
+}
 
 static VALUE thgroup_s_alloc _((VALUE));
@@ -9895,5 +10025,5 @@ thgroup_s_alloc(klass)
     struct thgroup *data;
 
-    group = Data_Make_Struct(klass, struct thgroup, 0, free, data);
+    group = Data_Make_Struct(klass, struct thgroup, thgroup_mark, free, data);
     data->enclosed = 0;
     data->group = group;
@@ -9952,5 +10082,5 @@ thgroup_add(group, thread)
 {
     rb_thread_t th;
-    struct thgroup *data;
+    struct thgroup *data, *old;
 
     rb_secure(4);
@@ -9972,13 +10102,83 @@ thgroup_add(group, thread)
 	rb_raise(rb_eThreadError, "can't move from the frozen thread group");
     }
-    Data_Get_Struct(th->thgroup, struct thgroup, data);
-    if (data->enclosed) {
+    Data_Get_Struct(th->thgroup, struct thgroup, old);
+    if (old->enclosed) {
 	rb_raise(rb_eThreadError, "can't move from the enclosed thread group");
     }
 
+    --old->count;
+    ++data->count;
     th->thgroup = group;
     return group;
 }
 
+static VALUE
+thgroup_wait(group)
+    VALUE group;
+{
+    struct thgroup *data;
+    rb_thread_t th;
+    VALUE waiting, result;
+
+    Data_Get_Struct(group, struct thgroup, data);
+    switch (data->count) {
+      case 1:
+	if (curr_thread->thgroup != group) break;
+      case 0:
+	return Qnil;
+    }
+    if (!(waiting = data->waiting)) {
+	waiting = rb_ary_new();
+	OBJ_TAINT(waiting);
+	data->waiting = waiting;
+    }
+    rb_ary_push(waiting, curr_thread->thread);
+    curr_thread->status = THREAD_STOPPED;
+    curr_thread->wait_for = 0;
+    curr_thread->join = 0;
+    rb_thread_schedule();
+    th = curr_thread->join;
+    curr_thread->join = 0;
+    result = th ? th->thread : Qnil;
+    if (rb_block_given_p()) {
+	result = rb_yield(result);
+    }
+    return result;
+}
+
+static void
+thgroup_notify(group, thread)
+    VALUE group;
+    rb_thread_t thread;
+{
+    struct thgroup *data;
+    rb_thread_t th;
+    VALUE waiting;
+    int i;
+
+    Data_Get_Struct(group, struct thgroup, data);
+    --data->count;
+    waiting = data->waiting;
+    if (!waiting || !RARRAY(waiting)->len) return;
+    for (i = 0; i < RARRAY(waiting)->len; ++i) {
+	th = (rb_thread_t)RDATA(RARRAY(waiting)->ptr[i])->data;
+	if (!rb_thread_dead(th)) {
+	    rb_thread_ready(th);
+	    th->join = thread;
+	}
+    }
+    rb_ary_clear(waiting);
+}
+
+static VALUE
+thgroup_count(group)
+    VALUE group;
+{
+    struct thgroup *data;
+
+    Data_Get_Struct(group, struct thgroup, data);
+    return INT2FIX(data->count);
+}
+
 void
 Init_Thread()
@@ -10027,4 +10227,5 @@ Init_Thread()
     rb_define_method(rb_cThread, "priority=", rb_thread_priority_set, 1);
     rb_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
+    rb_define_method(rb_cThread, "group", rb_thread_group, 0);
 
     rb_define_method(rb_cThread, "[]", rb_thread_aref, 1);
@@ -10047,4 +10248,6 @@ Init_Thread()
     rb_define_method(cThGroup, "enclosed?", thgroup_enclosed_p, 0);
     rb_define_method(cThGroup, "add", thgroup_add, 1);
+    rb_define_method(cThGroup, "wait", thgroup_wait, 0);
+    rb_define_method(cThGroup, "count", thgroup_count, 0);
     thgroup_default = rb_obj_alloc(cThGroup);
     rb_define_const(cThGroup, "Default", thgroup_default);


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next