
#13656: Consider implementing atomicModifyMutVar# in Haskell -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: task | Status: new Priority: low | Milestone: 8.4.1 Component: Runtime | Version: 8.2.1-rc2 System | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I believe we could implement `atomicModifyMutVar#` in Haskell, rather than making it a primop. This seems like a simpler/cleaner approach (among other things, it gets a perfectly legitimate type signature!), but we'd have to see how it affects performance. I think something like this should work: {{{#!hs atomicModifyMutVar# :: MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #) atomicModifyMutVar# mv f s = case readMutVar# mv s of { (# s', old #) -> let f_old = f old in case casMutVar# mv old (fst $ f_old) s of { (# s', unchanged, new #) -> case unchanged of 0# -> (# s', snd f_old #) _ -> atomicModifyMutVar# mv f s' }} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13656 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler