#5926: Add strict versions of modifyIORef and atomicModifyIORef
---------------------------------+------------------------------------------
    Reporter:  joeyadams         |       Owner:  simonmar               
        Type:  feature request   |      Status:  new                    
    Priority:  normal            |   Milestone:  7.6.1                  
   Component:  libraries/base    |     Version:  7.4.1                  
    Keywords:                    |          Os:  Unknown/Multiple       
Architecture:  Unknown/Multiple  |     Failure:  Runtime performance bug
  Difficulty:  Unknown           |    Testcase:                         
   Blockedby:                    |    Blocking:                         
     Related:                    |  
---------------------------------+------------------------------------------
Changes (by simonmar):

  * owner:  => simonmar
  * difficulty:  => Unknown
  * milestone:  => 7.6.1


Comment:

 Ok, I'll apply your patch as is.  There's another variant of strict
 `atomicModifyIORef` that I have been wanting to experiment with:

 {{{
 atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b
 atomicModifyIORef' (IORef (STRef r#)) f = IO $ \s0 -> loop s0
   where
     loop s0 =
       case readMutVar# r# s0     of { (# s1, a #) ->
       let !(a',b) = f a in
       case casMutVar# r# a a' s1 of { (# s2, ok, _ #) ->
       case ok of { 0# -> (# s2, b #); _ -> loop s2 }}}
 }}}

 This is like a mini-STM transaction that evaluates `f a` and then attempts
 to compare-and-swap the result in.  Since evaluating `f a` might take an
 arbitrary amount of time, the CAS might fail, and we have to loop.  On the
 other hand, using this we can avoid ever writing thunks into the `IORef`,
 which avoids any problems with black holes.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5926#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to