E
Earle Clubb
Can anyone explain this behavior? If the system time is set backward,
the sleep method in the thread sleeps until the system clock has caught
back up to the original time. The main thread does not display this
behavior.
The following script demonstrates the issue (run as root or sudo):
--------------------
#!/usr/bin/ruby -w
t = Thread.new do
20.times do |i|
puts "TH:#{Time.now}"
sleep 1
end
end
20.times do |i|
puts "MN:#{Time.now}"
sleep 1
if i == 5
now=Time.now
now+=ARGV[0].to_f
puts "Changing time to: #{now}"
`date -s "#{now}"`
end
end
t.join
--------------------
Running the script with and arg of -4 causes the thread to sleep for 5
seconds after the time change, but the main thread keeps on ticking
along. An arg of +4 causes no problems.
Earle
the sleep method in the thread sleeps until the system clock has caught
back up to the original time. The main thread does not display this
behavior.
The following script demonstrates the issue (run as root or sudo):
--------------------
#!/usr/bin/ruby -w
t = Thread.new do
20.times do |i|
puts "TH:#{Time.now}"
sleep 1
end
end
20.times do |i|
puts "MN:#{Time.now}"
sleep 1
if i == 5
now=Time.now
now+=ARGV[0].to_f
puts "Changing time to: #{now}"
`date -s "#{now}"`
end
end
t.join
--------------------
Running the script with and arg of -4 causes the thread to sleep for 5
seconds after the time change, but the main thread keeps on ticking
along. An arg of +4 causes no problems.
Earle