← Back to context

Comment by ori_b

7 years ago

Volatile is not a memory barrier. Different threads can observe reordered accesses regardless of volatile.

There's a reason that it's been proposed for removal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p115...)

Where did you see the article claim it was a memory barrier?

  • It doesn't say it's a memory barrier, but it absolutely has to be for the code to work.

    I agree I should be careful with "first-order approximations", but honestly I was being gentle because I do love drdobbs. But all of the things it talked about have been replaced with things that aren't broken in subtle and hard to debug way.

    Volatile simply cannot be used a general purpose, portable, synchronization primitive.

    • > It doesn't say it's a memory barrier, but it absolutely has to be for the code to work.

      No, it doesn't say it because it's not trying to make the point that you assume it's trying to make. Honest question: did you fully read and digest the article before commenting? If so, tell me on precisely which line you saw a lack of a memory barrier causing a problem (describe the race condition & bug you found) and explain how exactly you found that to undermine the point of the article.

      3 replies →

  • The code in the article requires memory barriers. It doesn't have them. It's broken code.

    The author is using volatile as though it implied a barrier.

    • > The code in the article requires memory barriers. It doesn't have them. It's broken code.

      > The author is using volatile as though it implied a barrier.

      No, you're just not reading the article. Please go read the article. And I don't mean skim. I mean actually read it with the assumption that you have zero clue what it's going to say, because that's more accurate than your current assumption. Then if you still think you're correct, please explain to exactly which line(s) in the code are broken and how precisely that actually undermines the points the article has been making. You will struggle to do this.

      In case it helps, for your reference: the author isn't, and never was, a random C++ dummy.

      11 replies →