Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,273
    • Issues 4,273
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 413
    • Merge Requests 413
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8972

Closed
Open
Opened Apr 08, 2014 by tibbe@trac-tibbe

Investigate adding fast compare-and-swap Int type/primops

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:

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.

Trac metadata
Trac field Value
Version 7.9
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
7.10.1
Milestone
7.10.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8972