[GHC] #8972: Investigate adding fast compare-and-swap Int type/primops
GHC
ghc-devs at haskell.org
Tue Apr 8 12:13:32 UTC 2014
#8972: Investigate adding fast compare-and-swap Int type/primops
------------------------------------+-------------------------------------
Reporter: tibbe | Owner: tibbe
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.9
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
------------------------------------+-------------------------------------
I've received reports that using `IORef Int` and `atomicModifyIORef` to
implement an atomic counter in the ekg package has become a bottleneck for
some of its users. These users update the counter thousands of times per
second, using multiple threads.
I will investigate whether adding a dedicated atomic `Int` reference type
will offer significant speed improvements. Such a type can also be used to
implement cheaper locks (by using bits in the int to represent different
lock states, such as reader/write locks.)
Lets call this new type `AtomicIntRef` for now. This new type needs to
support at least these functions:
{{{#!haskell
add :: AtomicIntRef -> Int -> IO Int
set :: AtomicIntRef -> Int -> IO ()
get :: AtomicIntRef -> IO Int
}}}
`add` would be implemented using the `lock` and `xaddq` instructions.
`set` and `get` are just simple loads and stores on x86, as these are
atomic.
We might also want to consider having other functions, such as a `cas`.
Furthermore, there are subtleties with memory barriers that might motivate
having barrier/barrier-less versions of some functions.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8972>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list