bug(?) in unblockThread?

Hal Daume t-hald@microsoft.com
Tue, 5 Aug 2003 08:34:32 -0700


I've implemented timeouts as described in:

=20
http://www.haskell.org/pipermail/glasgow-haskell-users/2001-April/001816
.html

My implementation follows:

timeout secs onTimeout action =3D do
  parent <- myThreadId
  i      <- newUnique
  block $ do
    timeoutT <- forkIO (timeoutThread secs parent i)
    catchDyn
      (unblock $ do
         result <- action
         killThread timeoutT
         return result)
      (\exception ->
         case exception of
           TimeOut u | u =3D=3D i -> unblock onTimeout
           _ -> do killThread timeoutT; throwDyn exception)
  where
    timeoutThread secs parent i =3D do
      threadDelay (secs * 2000);
      throwTo parent (DynException (toDyn (TimeOut i)))

which is basically just a rewrite of the amove url (except for the
multiplier in the call the threadDelay, which needs to be a lot smaller
than they had, for some reason).

However, I cannot seem to run this:

*Main> let loop :: IO () =3D threadDelay 100 >> loop >> return ()
*Main> timeout 1 (return ()) loop
<interactive>: internal error: unblockThread (I/O): TSO not found
    Please report this as a bug to glasgow-haskell-bugs@haskell.org,
    or http://www.sourceforge.net/projects/ghc/

Process ghci exited abnormally with code 254


I put the threadDelay in the loop to prevent a stack overflow.  This is
on Win32, GHC 6.0.  Any thoughts?  The same thing happens when this is
compiled, so it's not a ghci thing.

The same code seems to work fine on Linux and Solaris.  Is this a win32
thing?  If it is, is there another way I can get the same effect?



--
 Hal Daume III                                   | hdaume@isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume