# \[bug:trunk\] prime and timeout

**URL:** <https://www.ruby-forum.com/t/bug-trunk-prime-and-timeout/177102>\
**Category:** Development\
**Created:** [October 11, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/bug-trunk-prime-and-timeout/177102 "2009-10-11T19:56:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [October 11, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/bug-trunk-prime-and-timeout/177102/1 "2009-10-11T19:56:42Z")

</div>

e$B$?$^$K!“e(Brubyspec e$B$,0J2\<$N$h$&$K\<:GT$9$k$3$H$,$”$j$^$9!#e(B

[http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20091008T160610.log.txt.gz](http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20091008T160610.log.txt.gz)  
:

| 53)  
| Prime#each when an instance created via Prime.new infinitely iterates the given block passing a prime FAILED  
| Expected Timeout::Error  
| but got SpecExpectationNotMetError (Expected false to be true)  
| /home/akr/chkbuild/tmp/build/ruby-trunk/20091008T160610/rubyspec/library/prime/each\_spec.rb:41:in `block (2 levels) in <top (required)>' | /home/akr/chkbuild/tmp/build/ruby-trunk/20091008T160610/rubyspec/library/prime/each_spec.rb:17:in `\<top (required)\>’

e$B5-O?$rD4$Y$k$H:#G/$Oe(B 15e$B2s$[$I\<:GT$7$F$$$^$9!#e(B

% zgrep ‘Prime#each infinitely iterates the given block passing a prime  
FAILED’ 2009_log_  
20090501T201000.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090817T235403.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090820T061900.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090820T225200.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090822T121606.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090825T035002.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090906T105301.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090911T115004.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090918T210300.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090919T041101.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090923T213200.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090929T153305.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090930T023500.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20090930T090400.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED  
20091008T160610.log.txt.gz:Prime#each infinitely iterates the given  
block passing a prime FAILED

e$B$F$-$H$&$KD4$Y$F$_$k$H!“$I$&$be(B prime e$B$,e(B timeout  
e$B$GCfCG$5$l$ke(B  
e$B$H!”$=$l0J9_$KJQ$Je(B (e$BAG?t$G$J$$e(B)  
e$BCM$,@8@.$5$l$k$3$H$,$"$k$h$&e(B  
e$B$G$9!#e(B

% ./ruby -rtimeout -rprime -ve ’  
e = Prime.instance  
begin  
timeout(0.01) {  
e.each {|v| p v if (2…Math.sqrt(v)).any?{|n| v%n == 0 } }  
}  
rescue Timeout::Error  
retry  
end  
’  
ruby 1.9.2dev (2009-10-11 trunk 25297) [i686-linux]  
1369  
1369  
1517  
1591  
1369  
1517  
1517  
1369  
…

e$B$3$N%9%/%j%W%H$Oe(B Prime.instance.each e$B$,AG?t$G$J$$CM$r@8@.$7e(B  
e$B$?$H$-$K$=$NCM$rI=\<($7$^$9!#$?$H$($P!“e(B1369 e$B$Oe(B 37\*37  
e$B$J$N$GAGe(B  
e$B?t$G$O$”$j$^$;$s!#e(B

e$B%?%$%_%s%0$,4X78$9$k$h$&$J$N$G!"2?$bI=\<($5$l$J$+$C$?$iCfCG$7e(B  
e$B$F7+$jJV$7;n$7$F$_$F$/$@$5$$!#e(B

e$B$^$!!"e(Btimeout e$B$N$d$j$+$?$,4b$J$N$b3N$+$G$9$,!"1F6A$,8e$r$R$/e(B  
prime e$B$N$D$/$j$b$h$m$7$/$J$$$s$8$c$J$$$G$7$g$&$+!#e(B

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [October 11, 2009, 9:23pm UTC](https://www.ruby-forum.com/t/bug-trunk-prime-and-timeout/177102/2 "2009-10-11T21:23:21Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Tanaka A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> e$B$F$-$H$&$KD4$Y$F$_$k$H!“$I$&$be(B prime e$B$,e(B timeout e$B$GCfCG$5$l$ke(B  
> e$B$H!”$=$l0J9_$KJQ$Je(B (e$BAG?t$G$J$$e(B) e$BCM$,@8@.$5$l$k$3$H$,$"$k$h$&e(B  
> e$B$G$9!#e(B

> e$B%?%$%_%s%0$,4X78$9$k$h$&$J$N$G!"2?$bI=\<($5$l$J$+$C$?$iCfCG$7e(B  
> e$B$F7+$jJV$7;n$7$F$_$F$/$@$5$$!#e(B

Timeout::Error e$B$O$I$3$G$_$3$C$F$b$_$+$7$/$J$$$o$1$G$9$,!"0Je(B  
e$B2\<$N$h$&$Ke(B prime.rb e$B$NFCDj$N\>l=j$Ge(B Timeout::Error  
e$B$rH/@8$5$;e(B  
e$B$k$h$&$K$9$k$H!"3N\<B$K:F8=$7$^$9!#e(B

# % svn diff lib/prime.rb Index: lib/prime.rb

— lib/prime.rb (revision 25297)  
+++ lib/prime.rb (working copy)  
@@ -436,6 +436,7 @@  
lbound = orig\_len_32  
ubound = new\_len_32  
@table.fill(0xFFFF, orig\_len…new\_len)

- 

```
 raise Timeout::Error
 (3..Integer(Math.sqrt(ubound))).step(2) do |p|
  i, j = p.divmod(32)
  next if @table[i][j.div(2)].zero?

```

% ./ruby -Ilib -rtimeout -rprime -ve ’  
e = Prime.instance  
begin  
e.each {|v| }  
rescue Timeout::Error  
end  
p e.each {|v| break v if (2…Math.sqrt(v)).any?{|n| v%n == 0 } }  
’  
ruby 1.9.2dev (2009-10-11 trunk 25297) [i686-linux]  
259

e$B$3$3$Ge(B 259 e$B$Oe(B 7\*37 e$B$J$N$G!“AG?t$G$O$”$j$^$;$s!#e(B
