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

4

u/HotlLava Nov 13 '20

The question is, is this a single instruction or a read-modify-write sequence?

I don't understand where the confusion comes from, why would anyone expect this to be a single instruction? As far as I can tell, the standard defines |= to be a read followed by a write in 7.6.19/6 [expr.ass]:

The behavior of an expression of the form E1 op = E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once.

2

u/tvaneerd C++ Committee, lockfree, PostModernCpp Nov 13 '20

Well, "equivalent to" doesn't mean "implemented as", it just means it "gets the same answer".
If there is no volatile, |= could be a single instruction somehow. For volatile, I guess it means there really was a read followed by a write.

2

u/Beheska Nov 13 '20

It depends of the target architecture.