Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does `threadDelay (maxBound :: Int)` trip a GHC bug or what?

Tags:

haskell

ghc

I want my program to basically lockup forever and the first idea I had was:

threadDelay (maxBound :: Int)

This gave some spurious warnings:

Prelude> import Control.Concurrent
Prelude Control.Concurrent> threadDelay 10
Prelude Control.Concurrent> threadDelay (maxBound :: Int)
<interactive>: c_poll: invalid argument (Invalid argument)
<interactive>: ioManagerWakeup: write: Bad file descriptor

Did I do wrong or did GHC?

like image 923
Michael Fox Avatar asked Aug 06 '15 01:08

Michael Fox


1 Answers

This seems to be a known GHC bug, with some progress made (though not all configurations appear to be fixed yet).

In the meantime, you could use forever (threadDelay (2^20)) or similar as a workaround; 2^20 ought to be far enough away from maxBound to avoid this bug, and waking up once a second for a few cycles should be quite easy on your system.

like image 103
Daniel Wagner Avatar answered Oct 27 '22 00:10

Daniel Wagner