Hacker News new | past | comments | ask | show | jobs | submit login

> 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.

Your comments in this thread have broken the HN guidelines. Would you mind reviewing them and sticking to the rules when posting here? We'd appreciate it.


Getting personal, bringing up whether someone read an article properly, making uncharitable interpretations of other comments, snarking, and posting in the flamewar style are all things they ask you not to do and which we're trying to avoid here. Not that your comments were anything like as bad as some that we see, but even in seed form these things have ill effects.

Hi dang, thanks for the heads up (and yes, I'll review them). Trouble I've been having is I feel I already tried to follow the tips in the guideline in my initial comments (see [1]), but it didn't work -- people still commented claiming the article is recommending the opposite of what it's actually claiming, meaning they clearly did not read all of it. I'm stuck on what to do. If I can't explicitly tell them to go read the article, then what is the proper response?

Edit: Someone deleted one of their replies here. Just wanted to say thanks, I read it and I think it'll be helpful moving forward.

[1] https://news.ycombinator.com/item?id=20430310

> If I can't explicitly tell them to go read the article, then what is the proper response?

"This isn't what the article says. For instance, in paragraph n, the author states 'x, y and z.'"

This is basically what I tried in the comment of mine that I linked to, but it only works if they make a specific claim that the article refutes. It doesn't really work in response to "this article is very bad"...

> You, who've surely carefully read the article, understood it in its entirety, and played around with the notion to get a feel for its upsides and downsides, very insightfully reduced it all down to "very bad advice" with zero elaboration. You find that compelling?

I’m pretty sure you did not try to follow the guideline in your initial comments. (see [0])

[0] https://news.ycombinator.com/item?id=20430270

Yes, not in that comment. I was at a loss on how to reply to a comment that just trashed the article as "very bad" and left it at that; I'm thinking maybe I shouldn't have replied at all. But I tried to do things a little better in the next one. I failed regardless, though, so that's why I'm hoping someone can offer a new approach.

> Just like its better-known counterpart const, volatile is a type modifier. It's intended to be used in conjunction with variables that are accessed and modified in different threads.

Simply not true. It has limited use with memory mapped I/O (although even there it misses necessary guarantees), but is not intended to work with threads.

> So all you have to do to make Gadget's Wait/Wakeup combo work is to qualify flag_ appropriately:

    class Gadget
        ... as above ...
        volatile bool flag_;
Is not correct, and will not work reliably.

I spent some time working with Andrei at Facebook, and he's a smart guy, but this article is wrong.

Don't do what he says here.

Volatile needs to go away.

He's describing the current state of affairs in that statement and providing background context, which was that volatile was seen as a solution to the memory barrier issue at that time, which we know to be incorrect now, but which was the closest approximation the C++ standard had to a half-solution at the time. That's NOT the point of the aricle, it's just background context for 2001 readers. There's a whole article after that which does not tell you to use volatile that way, and the entire reason I posted it was that part. Did you read past that paragraph at all, till the end? Did you understand what the article was actually trying to tell you, or did you just try to find a code snippet that didn't look right without bothering to read the full article? Did you see he literally advises you in the end: "DON'T use volatile directly with primitive types"? The entire point of the article is to tell you about a use case that is explicitly not the one you're imagining.

The paragraph where he claims that volatile works?

The paragraph where he says "DON'T use volatile directly with primitive types".

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact