David Feuer
2018-06-23 08:14:51 UTC
Currently, atomicWriteIORef is implemented using atomicModifyIORef. This is
not ideal: the latter allocates memory while the former shouldn't need to.
In the process of writing alternative implementations, I realized that we
can efficiently support an atomic operation that replaces the value in an
IORef, returning the previous value. I propose that we add, to Data.IORef,
a function to do so:
atomicReplaceIORef :: IORef a -> a -> IO a
not ideal: the latter allocates memory while the former shouldn't need to.
In the process of writing alternative implementations, I realized that we
can efficiently support an atomic operation that replaces the value in an
IORef, returning the previous value. I propose that we add, to Data.IORef,
a function to do so:
atomicReplaceIORef :: IORef a -> a -> IO a