Discussion:
Proposal: Add an atomic IORef replacement operation
David Feuer
2018-06-23 08:14:51 UTC
Permalink
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
Dr.Koster
2018-06-24 23:38:06 UTC
Permalink
+1, BTW. let's call it atomicSwapIORef to keep sync with MVar/TVar's counterpart.


·¢×ÔÎÒµÄiPhone

------------------ Original ------------------
From: David Feuer <***@gmail.com>
Date: Sat,Jun 23,2018 4:15 PM
To: Haskell Libraries <***@haskell.org>
Subject: Re: Proposal: Add an atomic IORef replacement operation



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
David Feuer
2018-06-25 01:00:39 UTC
Permalink
Yes, you're absolutely right about the name. My proposal is thus amended.
Post by Dr.Koster
+1, BTW. let's call it atomicSwapIORef to keep sync with MVar/TVar's counterpart.
发自我的iPhone
------------------ Original ------------------
*Date:* Sat,Jun 23,2018 4:15 PM
*Subject:* Re: Proposal: Add an atomic IORef replacement operation
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
atomicReplaceIORef :: IORef a -> a -> IO a
Loading...