[Haskell-cafe] threadDelay delays less time than expected (Windows)

Joey Hess id at joeyh.name
Thu Dec 29 16:27:41 UTC 2016


Thomas DuBuisson wrote:
> Not to be infuriating, but I think you should check and re-check your
> tooling is not using 32 bit values at any particular point.

Eg, 32 bit ghc can run on 64 bit Windows.

> (fromIntegral (86400000000 `mod` 2^32)) / 10^6 ~ 500 seconds which is
> your observation.  Any time you depend on `Int` to represent numbers
> near or greater than 2^28, or perhaps 2^31 in practice, you should
> think hard about bounds and implications regarding portability anyway.

It's easy to write something like threadDelay (24*60*60*msPerSec) and not
realize that's overflowed. The numbers involved seem small. And when if
you're developing on 64 bit, it's easy to ship code with that bug and not
realize until someone tries it on 32 bit.

Since Haskell time types generally avoid problems with overflow (eg
DiffTime isn't bounded), one can become complacent that this is another
class of problems that the good data types in Haskell prevent, and stop
worrying about time overflows, and then get bitten by this.

It would perhaps be good for the documentation for threadDelay to point
out that it can delay for a maximum of 71 minutes on 32 bit systems, and
point to the unbounded-delays package.

-- 
see shy jo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161229/2066da6c/attachment.sig>


More information about the Haskell-Cafe mailing list