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 6116089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:09:59+00:00 2026-05-23T15:09:59+00:00

I am new to multithreading world and started getting into it. I found threading

  • 0

I am new to multithreading world and started getting into it. I found threading requires synchronization. Volatile is no more a reliable thing. I would like to know if synchronization object are cacheable by compiler or at any stage?

Platform/languages used : c++, win32, Windows

In c++, volatile keyword is used for objects which can not be cached by CPUs. But today’s compilers do not strictly follow this. Is there is other way around to make synchronization objects non-cacheable (or other optimizations are not applied on those objects).

tl;dr: Are synchronization objects cacheable? If yes, how can you make it non-cacheable ?

  • 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-23T15:09:59+00:00Added an answer on May 23, 2026 at 3:09 pm

    I’m not sure I follow your question: compiler cache has almost nothing to do with multithreading. The only thing that a compiler cache would do is to increase your compilation speed by caching previous compilations.

    Synchronization objects can be “cached” since they’re any arbitrary object that you’ve decided to use for synchronization, but that has little effect on concurrency. The only thing that you need to care about when synchronizing is that when you have multiple threads contending for a resource, they must all synchronize on the same object in order to get read/write access to the resource.

    I’m going to take a wild guess, based on your mentioning of volatile, and assume that you’re worried a synchronization object may be cached in a thread’s local cache and changes to the synchronization object from one thread may not be visible to another thread. This, however, is a flawed idea:

    1. When you call lock() or synchronize() (depending on the language), all you need to care about is that the lock is performed on the same object regardless of the internal state of the object.
    2. Once you’ve acquired a lock on an object, any resource that you’re modifying within that lock scope will be modified by only one thread.
    3. Generally, you should use a synchronization object that will not change (ideally a readonly, const or final) and we’re only talking about the reference here, not the content of the object itself. Here is an example:

      object sync = new object();
      string something = “hello”:

      void ModifySomething()
      {
      sync = new object();// <– YOU SHOULD NEVER DO THIS!!
      lock(sync)
      {
      something = GenerateRandomString();
      }
      }

    Now notice that every time a thread calls ModifySomething, the synchronization object will be replaced by an new object and the threads will never synchronize on the same object, therefore there may be concurrent writes to something.

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

Sidebar

Related Questions

new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
I am relativity new to multithreading in Java, and I would like to know
I'm kinda new to Java, so haven't yet fully grasped the concept of multithreading.I
I am relatively new to multi-threading and want to execute a background task using
I'm very new to multithreading and lack experience. I need to compute some data
I am new to multithreading (and also to C#) so I hope this is
Let me preface this with the disclaimer that I am very new to multithreading
Sorry, I am very new to all this multithreading stuff... I'm working on a
My answer: After getting annoyed, I have found a solution. The problem was indeed
My multi-threading knowledge is still pretty rudimentary, so would really appreciate some pointers here.

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.