
#7970: Thread GC frees roots before thread actually finishes ---------------------------------+------------------------------------------ Reporter: joeyadams | Owner: simonmar Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Runtime System | Version: 7.6.3 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Runtime crash Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: 7170 | ---------------------------------+------------------------------------------ Comment(by joeyadams): Replying to [comment:1 simonmar]:
This is technically not a bug - the thread is unreachable when it is deadlocked, and so is the weak pointer.
It only makes sense to call a thread "unreachable" if it will never run again. But when the RTS detects an unreachable thread and prods it with `NonTermination`, the thread continues running and accessing its local variables, meaning it should be considered reachable again. Here are some valid solutions, based on my understanding: 1. Treat a thread as reachable until it actually finishes or dies. Downside: deadlocked threads would no longer be GCed. 2. Don't throw `BlockedIndefinitelyOnMVar`, `NonTermination`, etc., just free the thread. This keeps the "unreachable" interpretation valid. Downside: manually-managed resources (including those managed with bracket) would be leaked. This is like (1), but at least allows Haskell objects to be GCed. 3. When the RTS detects a deadlocked thread, treat it as reachable again before making it throw an exception. This keeps the current behavior, but seems difficult to implement. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7970#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler