on master help sign in
adding comments about weak reference to ThreadId.
commitbc26f8a74ffc6983e7af0bed16a507d9efc89327 authorKazu Yamamoto <kazu@iij.ad.jp> dateThu 10 Oct 2013, 17:43 (13 years ago) parent504d91f
1 file changed+5
warp/Network/Wai/Handler/Warp/Timeout.hs+5
warp/Network/Wai/Handler/Warp/Timeout.hs+5
@@ -121,6 +121,11 @@ registerKillThread m = do
121121 wtid <- myThreadId >>= mkWeakThreadId
122122 register m $ killIfExist wtid
123123
124+-- If ThreadId is hold referred by a strong reference,
125+-- it leaks even after the thread is killed.
126+-- So, let's use a weak reference so that CG can throw ThreadId away.
127+-- deRefWeak checks if ThreadId referenced by the weak reference
128+-- exists. If exists, it means that the thread is alive.
124129killIfExist :: Weak ThreadId -> TimeoutAction
125130killIfExist wtid = deRefWeak wtid >>= maybe (return ()) killThread
126131