Ticket #4057 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Modifying TVar after calling always causes freeze/spin in GHCi

Reported by: Baughn Owned by: simonmar
Priority: high Milestone: 7.0.1
Component: GHCi Version: 6.12.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The attached code, if run under GHCi, causes GHCi to freeze while spinning the CPU. It works correctly when compiled, or if the ">> modifyTVar" part of f is commented out.

(For the curious: Yes, I believed always does what check does. Thankfully nothing had made its way into production code, because of this bug. The documentation should probably be clarified.)

Attachments

test.hs Download (468 bytes) - added by Baughn 3 years ago.

Change History

Changed 3 years ago by Baughn

Changed 3 years ago by igloo

  • priority changed from normal to high
  • failure changed from None/Unknown to Incorrect result at runtime
  • milestone set to 6.14.1

Thanks for the report.

I can reproduce this 99% of the time. Here's a version that doesn't need anything outside of validate:

import Control.Monad
import GHC.Conc
import System.IO

modifyTVar :: TVar Integer -> (Integer -> Integer) -> STM ()
modifyTVar t f = readTVar t >>= writeTVar t . f

main :: IO ()
main = do
  hSetBuffering stdout LineBuffering
  t <- newTVarIO 0
  let f = atomically $ do always (liftM2 (<=) (readTVar t) (return 5))
                          modifyTVar t succ
  putStrLn "f1"
  f
  putStrLn "f2"
  f
  putStrLn "v"
  v <- atomically $ readTVar t
  print v
*Main> main
f1
f2
^CInterrupted.
*Main> main
f1
f2
^CInterrupted.
*Main> 

Changed 3 years ago by simonmar

  • owner set to simonmar

Changed 3 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

Fixed:

Tue Jun 15 13:36:43 BST 2010  Simon Marlow <marlowsd@gmail.com>
  * stmAddInvariantToCheck: add missing init of invariant->lock (#4057)
Note: See TracTickets for help on using tickets.