Skip to content

Consider implementing atomicModifyMutVar# in Haskell

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:

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' }}
Trac metadata
Trac field Value
Version 8.2.1-rc2
Type Task
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information