Debugging concurrent program - no threads apparently running,
but RTS still doing something.
simonmarhaskell at gmail.com
Thu Feb 22 04:14:46 EST 2007
Alistair Bayley wrote:
> Below is a test case for a threading problem I can't figure out. It
> models a socket server (here I've replaced the socket with an MVar, to
> keep it simple). The idea is to have a listener which accepts incoming
> requests on the socket. When one arrives, it forks a handler thread to
> deal with the request, and returns to listening on the socket.
> The handler thread is run in parallel with a timeout thread. In the
> test case below, the handler takes too long, so the timeout thread
> completes and kills the handler.
> The problem is that when the main thread ends, the RTS doesn't stop
> for another 6 or so seconds. The only thread that runs this long is
> the handler (waitFor (secs 8.0)) but it has already been killed. So
> I'm scratching my head a bit.
Short answer: use -threaded.
The runtime is waiting for a worker thread to complete before it can exit; even
though your Haskell thread has been killed, there is still an OS thread
executing Sleep() which was started by threadDelay, and this OS thread has to
complete before the RTS can exit. We should really terminate the thread more
eagerly, but since this only affects the non-threaded RTS fixing it isn't a high
More information about the Glasgow-haskell-users