
Control.Concurrent provides the threadDelay function, which allows you to make the current thread sleep until T=now+X. However, I can't find any way of making the current thread sleep until T=X. In other words, I want to specify an absolute wakeup time, not a relative one. What's even more frustrating is that, reading the source code, it appears that the internal RTS primitive *is* actually using an absolute time, but this isn't exposed anywhere that I can get at. Is there any danger that this could be fixed at some point? (I might also interject something about Data.Time, which seems to hardly let me do anything, but strictly that's a seperate topic...)

On Thu, Jun 10, 2010 at 11:50 AM, Andrew Coppin
Control.Concurrent provides the threadDelay function, which allows you to make the current thread sleep until T=now+X. However, I can't find any way of making the current thread sleep until T=X. In other words, I want to specify an absolute wakeup time, not a relative one.
Modulo a small epsilon between the two actions, can't you just get the current time and subtract it from the target time? threadDelay is allowed to delay for too long anyway, so doing it this way does not lose you any correctness. Luke

Say, using System.Time.getClockTime.
Luke
On Thu, Jun 10, 2010 at 11:31 PM, Luke Palmer
On Thu, Jun 10, 2010 at 11:50 AM, Andrew Coppin
wrote: Control.Concurrent provides the threadDelay function, which allows you to make the current thread sleep until T=now+X. However, I can't find any way of making the current thread sleep until T=X. In other words, I want to specify an absolute wakeup time, not a relative one.
Modulo a small epsilon between the two actions, can't you just get the current time and subtract it from the target time? threadDelay is allowed to delay for too long anyway, so doing it this way does not lose you any correctness.
Luke

On Fri, Jun 11, 2010 at 3:34 PM, Luke Palmer
Say, using System.Time.getClockTime.
Luke
On Thu, Jun 10, 2010 at 11:31 PM, Luke Palmer
wrote: On Thu, Jun 10, 2010 at 11:50 AM, Andrew Coppin
wrote: Control.Concurrent provides the threadDelay function, which allows you to make the current thread sleep until T=now+X. However, I can't find any way of making the current thread sleep until T=X. In other words, I want to specify an absolute wakeup time, not a relative one.
Modulo a small epsilon between the two actions, can't you just get the current time and subtract it from the target time? threadDelay is allowed to delay for too long anyway, so doing it this way does not lose you any correctness.
Luke
This is a slightly different issue, but isn't there a potential problem with threadDelay? I noticed that internally threadDelay uses gettimeofday() as the absolute time source (on linux at least). Isn't there potential problem with this since wall-clock time isn't guaranteed to be monotonic increasing? On linux, I'd have thought the "right" thing to do would be to use clock_gettime(CLOCK_MONOTONIC) although that is probably not very portable. -- David

* David Powell
This is a slightly different issue, but isn't there a potential problem with threadDelay? I noticed that internally threadDelay uses gettimeofday() as the absolute time source (on linux at least). Isn't there potential problem with this since wall-clock time isn't guaranteed to be monotonic increasing? On linux, I'd have thought the "right" thing to do would be to use clock_gettime(CLOCK_MONOTONIC) although that is probably not very portable.
Good point -- I remember xmobar hanging after adjusting clock. Seems like this is the cause. -- Roman I. Cheplyaka :: http://ro-che.info/ "Don't let school get in the way of your education." - Mark Twain
participants (4)
-
Andrew Coppin
-
David Powell
-
Luke Palmer
-
Roman Cheplyaka