[Ruby 1.9 - Bug #4808][Open] thread_wait_for() eats 100% of CPU power

Issue #4808 has been reported by Hidetoshi Nagai.


Bug #4808: thread_wait_for() eats 100% of CPU power

Author: Hidetoshi Nagai
Status: Open
Priority: High
Assignee:
Category: core
Target version: 1.9.3
ruby -v: ruby 1.9.3dev (2011-06-01 trunk 31874) [x86_64-linux]

いつからかは把握できていませんが (少なくとも 1.9.2p0 では発生しません),
thread_wait_for() が CPU パワーを大量に消費するようになっています.

これが原因で,Ruby/Tk も CPU を 100 % 消費してしまいます.

このままリリースになってしまうとかなりまずいと思いますので,
優先度 High で急ぎ報告だけあげておきます.

以下はテスト用のコードです.
make 後に ruby -r ./th_wait_for.so -e ‘’ でお試しください.
----<th_wait_for.c>-----------------------------------------
#include “ruby.h”

void
Init_th_wait_for()
{
struct timeval t;

t.tv_sec = 0;
t.tv_usec = 10000; /* 10ms */

while(1) {
fprintf(stderr, “*”);fflush(stderr);
rb_thread_wait_for(t);
}
}

----<extconf.rb>--------------------------------------------
require ‘mkmf’
create_makefile(‘th_wait_for’);

$B$$$D$+$i$+$OGD0.$G$-$F$$$^$;$s$,(B ($B>/$J$/$H$b(B 1.9.2p0
$B$G$OH/@8$7$^$;$s(B)$B!$(B
thread_wait_for() $B$,(B CPU $B%Q%o!<$rBgNL$K>CHq$9$k$h$&$K$J$C$F$$$^$9!%(B

$B$3$l$,860x$G!$(BRuby/Tk $B$b(B CPU $B$r(B 100 % $B>CHq$7$F$7$^$$$^$9!%(B

$B$3$N$^$^%j%j!<%9$K$J$C$F$7$^$&$H$+$J$j$^$:$$$H;W$$$^$9$N$G!$(B
$BM%@hEY(B High $B$G5^$.Js9p$@$1$"$2$F$*$-$^$9!%(B

$B55%l%9$G$9$$$^$;$s!#:G6a(B Ruby/tk
$B$K(BCPU$B;HMQN($r2<$2$k%3%_%C%H$,$$$/$D$+(B
$BF~$C$F$$$k$h$&$G$9$,!"(Br31893
$B$G$OIT==J,$@$C$?$H$$$&$3$H$J$s$G$7$g$&$+!)(B
$B$=$l$H$b!"A4A3JL7o$N2~A1$J$N$G$7$g$&$+!)(B

$B$4LBOG$r$*$+$1$7$F$$$k$N$G$O$J$$$+$H?4G[$7$F$$$k$N$G65$($F$$$?$@$1$l$P(B
$B9,$$$G$9(B

Issue #4808 has been updated by Motohiro KOSAKI.

Status changed from Open to Assigned
Assignee set to Motohiro KOSAKI


Bug #4808: thread_wait_for() eats 100% of CPU power

Author: Hidetoshi Nagai
Status: Assigned
Priority: High
Assignee: Motohiro KOSAKI
Category: core
Target version: 1.9.3
ruby -v: ruby 1.9.3dev (2011-06-01 trunk 31874) [x86_64-linux]

いつからかは把握できていませんが (少なくとも 1.9.2p0 では発生しません),
thread_wait_for() が CPU パワーを大量に消費するようになっています.

これが原因で,Ruby/Tk も CPU を 100 % 消費してしまいます.

このままリリースになってしまうとかなりまずいと思いますので,
優先度 High で急ぎ報告だけあげておきます.

以下はテスト用のコードです.
make 後に ruby -r ./th_wait_for.so -e ‘’ でお試しください.
----<th_wait_for.c>-----------------------------------------
#include “ruby.h”

void
Init_th_wait_for()
{
struct timeval t;

t.tv_sec = 0;
t.tv_usec = 10000; /* 10ms */

while(1) {
fprintf(stderr, “*”);fflush(stderr);
rb_thread_wait_for(t);
}
}

----<extconf.rb>--------------------------------------------
require ‘mkmf’
create_makefile(‘th_wait_for’);

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: KOSAKI Motohiro [email protected]
Subject: [ruby-dev:43611] Re: [Ruby 1.9 - Bug #4808][Open]
thread_wait_for() eats 100% of CPU power
Date: Thu, 2 Jun 2011 22:37:45 +0900
Message-ID: [email protected]

$B$$$D$+$i$+$OGD0.$G$-$F$$$^$;$s$,(B ($B>/$J$/$H$b(B 1.9.2p0
$B$G$OH/@8$7$^$;$s(B)$B!$(B
thread_wait_for() $B$,(B CPU $B%Q%o!<$rBgNL$K>CHq$9$k$h$&$K$J$C$F$$$^$9!%(B

$B$3$l$,860x$G!$(BRuby/Tk $B$b(B CPU $B$r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