Proposal: Add an atomic IORef replacement operation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Proposal: Add an atomic IORef replacement operation

David Feuer
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add an atomic IORef replacement operation

winter
+1, BTW. let's call it atomicSwapIORef to keep sync with MVar/TVar's counterpart.



------------------ Original ------------------
From: David Feuer <[hidden email]>
Date: Sat,Jun 23,2018 4:15 PM
To: Haskell Libraries <[hidden email]>
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Proposal: Add an atomic IORef replacement operation

David Feuer
Yes, you're absolutely right about the name. My proposal is thus amended.

On Sun, Jun 24, 2018, 7:38 PM Dr.Koster <[hidden email]> wrote:
+1, BTW. let's call it atomicSwapIORef to keep sync with MVar/TVar's counterpart.

发自我的iPhone


------------------ Original ------------------
From: David Feuer <[hidden email]>
Date: Sat,Jun 23,2018 4:15 PM
To: Haskell Libraries <[hidden email]>
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

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries