Sleep function duration changes when system clock is modifie


#1

My problem is related to the behaviour of sleep function. If, during
the execution of sleep function, I change the system clock of my PC,
sleep function will not recover from sleeping when it should.

Example:

My controller:

def index
logger.info “Start sleeping at:”+Time.now.to_s
sleep 5
logger.info “Sleeping finished at:”+Time.now.to_s
end

Everythink works well if I don’t change the system time during the
execution of sleep function.
However, if during the execution of sleep function I shift the system
time, let’s say 1 minute back, I’ll need to wait 1 minute and 5
seconds until the sleep function finishes.

I’d need to force sleep function to sleep always 5 seconds, even if
the system time changes during the call of the sleep function.

If I try somethink similar in pure ruby (no rails), everythink works
as expected, I can change system time without any consequences to the
behaviour of sleep function.

I am using Rails 1.2.1 under WinXP.

Thanks for your help.


#2

Jan wrote:

My problem is related to the behaviour of sleep function. If, during
the execution of sleep function, I change the system clock of my PC,
sleep function will not recover from sleeping when it should.

While odd, why is this really a problem? You shouldnt be manually
changing the system clock very often.


#3

The server application will be running on customer’s PC and the sleep
function is used in a background thread. In these conditions, the
manual change of system clock may happen and I would’nt like if this
freezed the background thread.


#4

Bump…I am also experiencing this problem with Fedora Core 6 & 7

http://www.ruby-forum.com/topic/123178#new
http://www.ruby-forum.com/topic/130593#new