Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix sleep() with huge values failing to sleep
Imagine you get into a cryogenic chamber, hoping to be whisked into the distant
future exactly 317,097,919 years, 50 weeks, 2 days, 17 hours, 46 minutes, and
40 seconds in the future. The control software is written in Perl 6 and the lazy
programmer just stuck a sleep() function in there. Unfortunately, you will be
defrosted instantly, because there's a bug with such huge numbers and sleep()
doesn't sleep at all! Of course, another lazy programmer may assume such huge
amounts of time are practically infinity and fix the bug with such assumption,
but then you will be frozen... forever! Therefore, we must fix the sleep()
function to handle huge chunks of time by splitting them into several sleeps in
intervals of 1e16 seconds (approximatelly max that JVM can handle), thereby
guaranteeing all cryogenic chambers will function correctly.

Fixes RT130170: #https://rt.perl.org/Ticket/Display.html?id=130170
  • Loading branch information
zoffixznet committed Nov 26, 2016
1 parent a9654c0 commit c797d3f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/Date.pm
Expand Up @@ -198,6 +198,9 @@ sub sleep($seconds = Inf --> Nil) {
if $seconds == Inf || nqp::istype($seconds,Whatever) {
nqp::sleep(1e16) while True;
}
elsif $seconds > 1e16 {
nqp::sleep(1e16) for ^$seconds.Num.polymod: 1e16 xx *;
}
elsif $seconds > 0 {
nqp::sleep($seconds.Num);
}
Expand Down

0 comments on commit c797d3f

Please sign in to comment.