Erik de Castro Lopo pushed to branch wip/fix-9809 at Glasgow Haskell Compiler / GHC
Commits:
-
59d99193
by Erik de Castro Lopo at 2026-10-26T12:33:50+11:00
3 changed files:
Changes:
| ... | ... | @@ -275,4 +275,5 @@ |
| 275 | 275 | /weak001
|
| 276 | 276 | /T9395
|
| 277 | 277 | /T9532
|
| 278 | +/T9809
|
|
| 278 | 279 | /T11555 |
| 1 | +-- #9809: when many threads registered timeouts at the same time, the
|
|
| 2 | +-- TimerManager published unevaluated timeout queues with atomicModifyIORef'.
|
|
| 3 | +-- The threads then built long chains of thunks and blocked on each other's
|
|
| 4 | +-- black holes, and the heap grew to hundreds of megabytes. all.T runs this
|
|
| 5 | +-- test with a heap limit that the old code exceeded.
|
|
| 6 | + |
|
| 7 | +import Control.Concurrent
|
|
| 8 | +import Control.Monad
|
|
| 9 | +import Data.IORef
|
|
| 10 | +import GHC.Conc (TVar, atomically, newTVarIO, readTVar, registerDelay, retry, writeTVar)
|
|
| 11 | + |
|
| 12 | +main :: IO ()
|
|
| 13 | +main = do
|
|
| 14 | + let n = 100000
|
|
| 15 | + ref <- newIORef []
|
|
| 16 | + registered <- newTVarIO (0 :: Int)
|
|
| 17 | + replicateM_ n . forkIO $ do
|
|
| 18 | + tv <- registerDelay 10
|
|
| 19 | + atomicModifyIORef' ref (\tvs -> (tv : tvs, ()))
|
|
| 20 | + atomically $ readTVar registered >>= writeTVar registered . (+ 1)
|
|
| 21 | + atomically $ do
|
|
| 22 | + r <- readTVar registered
|
|
| 23 | + when (r /= n) retry
|
|
| 24 | + readIORef ref >>= mapM_ waitFor
|
|
| 25 | + |
|
| 26 | +-- | Block until a delay has fired, so that the test also checks that the
|
|
| 27 | +-- TimerManager fires every timeout.
|
|
| 28 | +waitFor :: TVar Bool -> IO ()
|
|
| 29 | +waitFor tv = atomically $ readTVar tv >>= \fired -> unless fired retry |
| ... | ... | @@ -193,6 +193,12 @@ test('T7653', [when(opsys('mingw32'), skip), |
| 193 | 193 | omit_ways(prof_ways + ghci_ways)], compile_and_run, [''])
|
| 194 | 194 | test('T7787', normal, compile_and_run, [''])
|
| 195 | 195 | |
| 196 | +# Before the fix for #9809 this needed more than 256MB of heap.
|
|
| 197 | +test('T9809', [req_ghc_smp,
|
|
| 198 | + req_target_smp,
|
|
| 199 | + only_ways(['threaded1', 'threaded2', 'nonmoving_thr'])],
|
|
| 200 | + compile_and_run, ['-threaded -with-rtsopts="-N2 -M128m"'])
|
|
| 201 | + |
|
| 196 | 202 | test('topHandler01', [when(opsys('mingw32'), skip), js_broken(22261), req_process], compile_and_run, [''])
|
| 197 | 203 | test('topHandler02',
|
| 198 | 204 | [when(opsys('mingw32'), skip),
|