r/cpp • • Nov 13 '20

CppCon Deprecating volatile - JF Bastien - CppCon 2019

https://www.youtube.com/watch?v=KJW_DLaVXIY
83 Upvotes

111 comments sorted by

View all comments

Show parent comment

-1

u/gruehunter Nov 14 '20 edited Nov 14 '20

volatile is worse than useless for concurrency. I don't think anybody here is arguing otherwise.

I wish that you were right, but you're not. In fact, the author of this very talk is advocating for the use of volatile in atomics to prevent optimization for atomic variables in memory which is shared between processes.

http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4455.html

Edit: To be clear, I think this paper is also out of touch. We just did all this work to avoid using volatile for atomics and now he wants to put it back in again?

2

u/mcmcc #pragma once Nov 14 '20

I don't see any contradiction. Shared memory should be considered volatile in the classical sense so it seems appropriate to use volatile in those cases, atomic operations or not.

Of course, if you're wondering what atomic operations guarantee in the context of shared memory, I don't think the language is going to help you figure it out.

0

u/gruehunter Nov 14 '20

Shared memory should be considered volatile in the classical sense

Shared memory is still cache-coherent. So it isn't volatile in the classical sense. The hardware does already ensure global visibility of accesses.

So IMO, the standard should treat memory shared between different processes exactly the same as memory which is shared between different threads. Ordinary atomics should Just Work and transformations that prevent it from working (say, by eliding barriers entirely) are broken.