How to kill a thread in Haskell How to kill a thread in Haskell windows windows

How to kill a thread in Haskell


To expand on my comment above, you can't interrupt blocking foreign calls. You can, however, use nonblocking IO. In the case of the Network package, this means recvLen for strings, and recvFrom for bytestrings. I assume you're always specifying the threaded runtime as well?


One other thing to note is that GHC programs terminate when the main thread terminates. The liveness of child threads is unimportant. If you design your app such that you can always signal the main thread that it's time to terminate, it doesn't matter how blocked any child threads are.


In Posix environments you can terminate the entire process with:

-- | @'exitImmediately' status@ calls @_exit@ to terminate the process--   with the indicated exit @status@.--   The operation never returns.exitImmediately :: ExitCode -> IO ()

From the unix package. There may be a similar non-Posix feature under the Win32 package.

However, it is better to design your application such that your signalling mechanisms are respected, of course.