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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:47:19+00:00 2026-06-05T01:47:19+00:00

Am I the only who thinks so? [Real question in a second.] Besides the

  • 0

Am I the only who thinks so? [Real question in a second.]

Besides the great confusion about it, and its mixing with mutexes or other locking mechanisms, when I am dealing with thread safety situation, I always have to discard any use of volatile, because it simply does not do anything useful.

volatile “forbids any reordering or caching of read/writes”, but this is not of much use as long as volatile just tags a single object (and taints it, as it won’t be any longer a “normal” object).

Consider this:

Thread A            Thread B
reads vars
                    locks mutex (gets access)
locks mutex (waits)
                    writes some vars
                    releases mutex
reads vars again
releases mutex

Now, the compiler might want to optimize the two thread A’s reads saving some of the results in registers. You say I should declare those vars as volatile. I say that I don’t want to flag everything as volatile, because volatile is transparent as a stone and I have to duplicate 50% of my code to support volatile types. You (he) say that locking a mutex (at least a POSIX mutex) is either something that a compiler recognizes, and manages correctly, either it’s a call to a library (inaccessible to the compiler) that can change the world, so the compiler will not assume anything after such call. I say that this is too implementation dependent, very low level stuff (and I don’t want to browse dev docs for day to day programming). And worse, it can suddenly change if for some reason the “external library”, for any legit reason, becomes accessible to the compiler (maybe the author transforms the function in a template that has to be included in a header… whatever).

So, in my opinion, volatile is totally useless (and misleading), unless for some very low level stuff (device read maybe, but I’m not competent in such field).

Much better would be some other way to tell explicitly to the compiler that it has to discard any assumption about any variable, and every subsequent read must be a true read from memory. But I cannot imagine anything better than calling a dummy external function, and that would have the same issues that I have outlined before. Is there an elegant way to do so?

  • 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-05T01:47:21+00:00Added an answer on June 5, 2026 at 1:47 am

    The new C standard, C11, has what you are calling for. First of all, it has a thread model and a detailed “happened before” relation that extends to threads. And it has a atomic_thread_fence operation that does what you are searching for.

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

Sidebar

Related Questions

I am trying to find the makers of products who only make laptops and
Let me explain. Suppose I want to teach Python to someone who only speaks
I have a text file named num.txt who's only contents is the line 123
Quick one: Is it only I as the app administrator who can add the
I need a specific user who will be only used for reporting. That user
I have a problem that only occurs with users who have just signed up
I am really only a hobbyist, who has aspirations far too grand, that said,
It may be the case this is only possible through looping, but who knows.
I have a php/mysql application. There are users who have folders. Folders can only
I have a real estate agent client who wants a website to list the

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.