# \[Ruby 1.9 - Bug #4808\]\[Open\] thread\_wait\_for() eats 100% of CPU power

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698>\
**Category:** Development\
**Created:** [May 31, 2011, 11:57pm UTC](https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698 "2011-05-31T23:57:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 31, 2011, 11:57pm UTC](https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698/1 "2011-05-31T23:57:32Z")

</div>

Issue #4808 has been reported by Hidetoshi Nagai.

* * *

Bug #4808: thread\_wait\_for() eats 100% of CPU power

> **[Bug #4808: thread\_wait\_for() eats 100% of CPU power - Ruby master - Ruby...](https://redmine.ruby-lang.org/issues/4808)**
>
> Redmine

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’);

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 2, 2011, 3:38pm UTC](https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698/2 "2011-06-02T15:38:27Z")

</div>

> $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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 1, 2011, 6:40am UTC](https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698/3 "2011-06-01T06:40:31Z")

</div>

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

> **[Bug #4808: thread\_wait\_for() eats 100% of CPU power - Ruby - Ruby Issue...](https://redmine.ruby-lang.org/issues/4808)**
>
> Redmine

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’);

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 2, 2011, 11:15pm UTC](https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698/4 "2011-06-02T23:15:06Z")

</div>

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

From: KOSAKI Motohiro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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: [BANLkTi=removed\_email\_address@domain.invalid](mailto:BANLkTi=removed_email_address@domain.invalid)

> > $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$4$a$s$J$5$$!%J6$i$o$7$+$C$?$G$9$M!%(B  
$BEv=iJs9p$7$?LdBj$O(B r31893 $B$G2r\>C$7$^$7$?!%$"$j$,$H$&$4$6$$$^$9!%(B

$B$G$9$,!$$=$l$G$b$J$\*(B CPU $BMxMQN($,9b$+$C$?$N$G!$(B  
$B0JA0$H0[$J$kJ}K!$G(B thread $B@ZBX$(%?%$%\_%s%0$r7h$a$k$h$&$K$7$?$N$,(B  
$B$=$N8e$N(B patch $B$G$9!%(B  
$B\<j85$N4D6-$G$O!$(BCPU $BMxMQN($,(B patch $BE,MQA0$N(B 1/10  
$B$/$i$$$K$J$j$^$9!%(B

# $B@N$KHf$Y$F%^%7%s$,B.$/$J$C$F$$$k$3$H$b$"$j!$(B

# $B0JA0$N$d$jJ}$G$ODLMQ$7$J$/$J$C$F$$$?$h$&$G$9!%(B

$B8z2L$,Bg$-$$$N$G(B 1.9.2 $B$K$b(B backport  
$B$7$?J}$,$$$$$H$O;W$&$N$G$9$,!$(B  
$B%F%9%H4|4V$,==J,$G$O$J$$$3$H$,?4G[E@$G$9!%(B  
$BB?J,!$Bg\>fIW$@$m$&$H$O9M$($F$$$k$N$G$9$,!%!%!%(B

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 3, 2011, 11:04am UTC](https://www.ruby-forum.com/t/ruby-1-9-bug-4808-open-thread-wait-for-eats-100-of-cpu-power/207698/5 "2011-06-03T11:04:22Z")

</div>

> $B\<j85$N4D6-$G$O!$(BCPU $BMxMQN($,(B patch $BE,MQA0$N(B 1/10  
> $B$/$i$$$K$J$j$^$9!%(B  
> $B$J$k$[$I!#M}2r$G$-$^$7$?!#CzG+$K$"$j$,$H$&$4$6$$$^$9!#(B1/10$B$H$OAG@2$i$7$$$G$9$M(B
