[Haskell-cafe] scheduling an alarm

Thomas DuBuisson thomas.dubuisson at gmail.com
Tue Jan 26 02:19:53 EST 2010


1) Don't use System.Posix.Signals
It isn't necessary and makes your code less portable

2) The POSIX SIGALRM is used/caught by the RTS and that is why you are
seeing strange behavior.

3) Consider using Haskell exceptions from Control.Concurrent (throwTo).
Not sure what you want to do but you can always "myThreadId >>= \tid ->
forkIO $ threadDelay someDelayTime >> (throwTo tid someExceptionVal)"

Thomas

On Mon, Jan 25, 2010 at 10:25 PM, Brian Denheyer <briand at aracnet.com> wrote:

> I cobbled the following together from bits and pieces I found on
> mailing lists.  Seems straightforward, but the code I've included
> just sits there.
>
> The awaitSignal seems to be causing a problem, in that if I remove it
> (and don't call forever recursively) then I get my ALARM 5 sec later.
>
> Otherwise nothing.  The problem is that if I don't include awaitSignal,
> then, of course, forever is called just as fast as the CPU will go :-)
>
> Brian
>
>
> import System.Posix.Signals
> import System.IO
> import Control.Concurrent
>
> alarm =
>    do putStrLn "ALARM"
>       hFlush stdout
>       return ()
>
> forever =
>    do putStrLn "foo"
>       scheduleAlarm 5
>       awaitSignal Nothing
>       yield
>       forever
>
> main =
>    do installHandler realTimeAlarm (Catch alarm) Nothing
>       forever
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100126/e866a0d6/attachment.html


More information about the Haskell-Cafe mailing list