how to catch GHC "no threads to run" exception?
My program runs 3 threads, and after a few minutes' execution all threads come to a state that they all wait on some MVars, then the program halts with an error: test: no threads to run: infinite loop or deadlock? (test is my program name) My problem is that this behavior is actually desired, but how do I catch this exception and do some bookkeeping (closing external IO, etc.) and then a proper exit? Thanks in advance! Regards, .paul.
In local.haskell, you wrote:
test: no threads to run: infinite loop or deadlock? My problem is that this behavior is actually desired, but how do I catch this exception and do some bookkeeping (closing external IO, etc.) and then a proper exit?
You can wrap the `takeMVar' with Exception.catch. Note that Prelude.catch won't suffice. -- http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME http://news.bbc.co.uk: The Israeli army destroyed the bomber's family's house afterwards, a military statement said.
On Thu, Aug 01, 2002 at 11:27:06AM +0200, Volker Stolz wrote:
In local.haskell, you wrote:
test: no threads to run: infinite loop or deadlock? My problem is that this behavior is actually desired, but how do I catch this exception and do some bookkeeping (closing external IO, etc.) and then a proper exit?
You can wrap the `takeMVar' with Exception.catch. Note that Prelude.catch won't suffice.
Since I have 3 threads waiting on takeMVar, do I have to wrap all of them with Exception.catch? Regards, .paul.
In local.haskell, you wrote:
Since I have 3 threads waiting on takeMVar, do I have to wrap all of them with Exception.catch?
Yes. Especially since ghc-5.04, you cannot be sure which of the blocked threads will get killed first: http://haskell.org/pipermail/glasgow-haskell-users/2002-July/003779.html -- http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME http://news.bbc.co.uk: The Israeli army destroyed the bomber's family's house afterwards, a military statement said.
participants (3)
-
paul@thev.net -
paul@theV.net -
Volker Stolz