Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:45:10+00:00 2026-06-01T15:45:10+00:00

Can someone explain how atomicModifyIORef works? In particular: (1) Does it wait for a

  • 0

Can someone explain how atomicModifyIORef works? In particular:

(1) Does it wait for a lock, or optimistically try and retry if there’s contention (like TVar).
(2) Why is the signature of atomicModifyIORef different to the signature of modifyIORef? In particular, what is this extra variable b?

Edit: I think I’ve figured out the answer to (2), in that b is a value to be extracted (this can be empty if not needed). In a single threaded program, knowing the value is trivial, but in a multithreaded program, one may want to know what the previous value was at the time of the function being applied. I assume this is why modifyIORef doesn’t have this extra return value (as such usages of modifyIORef with this return value probably should use atomicModifyIORef anyway. I’m still interested in the answer to (1) though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:45:11+00:00Added an answer on June 1, 2026 at 3:45 pm

    atomicModifyIORef takes a r :: IORef a and a function f :: a -> (a, b) and does the following:

    It reads the value of r and applies f to this value, yielding (a',b). Then the r is updated with the new value a' while b is the return value. This read and write access is done atomically.

    Of course this atomicity only works if all accesses to r are done via atomicModifyIORef.
    Note that you can find this information by looking at the source [1].

    [1] https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-IORef.html#v:atomicModifyIORef

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain why the HashMap acts like it does in this example: Simple
Can someone explain how New works with the With keyword in this example from
Can someone explain the following behavior? Specifically, why does the function return a different
Can someone explain what does this statement do? #define CONST_SIG (void (*) () )
Can someone explain binary stripping to me? How effective is it (How much does
Can someone explain to me why this line works: conn = DriverManager.getConnection(jdbc:mysql://myWebsite.com:3306/schemaName?user=userX&password=passwordX); But this
Can someone explain why there is the need to add an out or in
Can someone explain to me how to set up cookieless domain? There are many
Can someone explain what this ajax code does? function ajaxProgress(){ //Math.random() is for bitchy
Can someone explain in clear language how the non-zero lookbehind assertion (?<=.) technically works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.