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

  • SEARCH
  • Home
  • 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 6087735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:54:15+00:00 2026-05-23T11:54:15+00:00

If I were to use some kind of algorithm that uses InterlockCompareExchange operations on

  • 0

If I were to use some kind of algorithm that uses InterlockCompareExchange operations on a variable in C++ that determines if a set of data is being written to by a particular thread (by creating my own little lock), how do I ensure that the interlocked operation that updated the value is immediately seen by the other thread if the data is being stored in say, level 2 cache on an i7.

I know that cache coherency is used to keep the data across caches of multi-core processors consistent, but what about the small frame of time when one core updates a variable with an interlock function and the cache checks and fixes coherency problems all while another core is checking that variable it has in its own cache? Would this problem be fixed if I ensured the variable that is having the InterlockCompareExchange operation is volatile so that changes are written directly to the memory? Am I correct to believe that a memory barrier (MemoryBarrier() on VS) does not ensure cache coherency but only ensures unwanted instruction reordering?

I hope my question isn’t too vague. I will try to answer any comments if I was. I don’t have any source code to post with this question as I don’t have any specific problems, but would like to know for future reference if there could be any problems with this, especially with c++0x having interlocks as part of its standard library.

Thank you.

  • 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-05-23T11:54:15+00:00Added an answer on May 23, 2026 at 11:54 am

    The compiler can’t reorder loads or stores across an interlocked function call, and the implementation will include whatever machine instructions are needed to make sure the CPU core won’t.

    Cache coherency is always maintained, the only thing you have to worry about is when the value actually gets written out from the instruction pipeline to cache, and that’s an ordering issue.

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

Sidebar

Related Questions

Do you need to use some kind of provider? Can you setup your own
I want to use some kind of trigger to change a button in my
Most of you certainly use some kind of bugtracker. Maybe internally only, once a
Is there any way to use some kind of captcha when we use the
I want to be able to open my website and use some kind of
For the ExcelPackage constructor you need a FileInfo object. I rather use some kind
...just like packages do. I use Emacs (maybe, it can offer some kind of
I need some advice on what kind of pattern(s) I should use for pushing/pulling
In the iphone game Tiny Tower, I'm guessing it uses some kind of simulation
Is there a way to use some kind of encryption (md5, hash, etc...) to

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.