Ticket #3049 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

STM with data invariants crashes GHC

Reported by: simonpj Owned by:
Priority: normal Milestone: 6.12.1
Component: Runtime System Version: 6.10.1
Keywords: Cc: ben.franksen@…, nicolas.pouillard@…, int-e@…, dbueno@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Ben Franksen writes: my ghc(i) crashes when using STM data invariants. This little piece of code demonstrates the problem:

module Bug where

import Control.Concurrent.STM

test = do
  x <- atomically $ do
    v <- newTVar 0
    always $ return True -- remove this line and all is fine
    return v
  atomically (readTVar x) >>= print

This is what ghci makes of it:

ben@sarun> ghci Bug.hs
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )
Ok, modules loaded: Bug.
*Bug> test
Loading package syb ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package stm-2.1.1.2 ... linking ... done.
zsh: segmentation fault  ghci Bug.hs

I am using ghc-6.10.1 freshly installed from source with just a 'cabal install stm' thrown after it.

BTW, the documentation for Control.Concurrent.STM.TVar lists... nothing. Similar with Control.Monad.STM. Well, at least the source link works, so one isn't completely lost... :-)

Attachments

maybe-fix-3049.dpatch.gz Download (98.1 KB) - added by int-e 4 years ago.
A possible fix for this problem. I'm not certain whether saving R1 like this is the right fix for all platforms. I'm also uncertain whether I've missed any places that need to know about the changed atomically frame layout.

Change History

Changed 4 years ago by guest

  • cc changed from ben.franksen@online.de to ben.franksen@online.de

FWIW, it segfaults in 6.8.2 too.

Changed 4 years ago by igloo

  • milestone set to 6.12.1

Changed 4 years ago by int-e

Here's a more enlightening example:

import GHC.Conc

main = do
    t <- atomically $ do
        alwaysSucceeds (return 42)
        return 23
    print t

This will print 42 instead of 23. I believe that if any invariants are checked, the result of atomically will be that of the last invariant.

Changed 4 years ago by ertai

  • cc nicolas.pouillard@… added

Changed 4 years ago by int-e

A possible fix for this problem. I'm not certain whether saving R1 like this is the right fix for all platforms. I'm also uncertain whether I've missed any places that need to know about the changed atomically frame layout.

Changed 4 years ago by int-e

  • cc int-e@… added

Changed 4 years ago by dbueno

  • cc dbueno@… added

Changed 4 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed
  • component changed from Compiler to Runtime System

Fixed:

Wed Jun 24 07:15:30 PDT 2009  Simon Marlow <marlowsd@gmail.com>
  * propagate the result of atomically properly (fixes #3049)

the patch came from Tim Harris, with a couple of fixes by me. Looks like Tim based his patch on int-e's patch attached to this ticket.

Note: See TracTickets for help on using tickets.