Do non-static member variables in a C++ struct/class need to be marked as volatile to be treated as volatile in a member function?

Marking a member function volatile is like marking it const; it means that the receiver object is treated as though it were declared as a volatile T*. Consequentially, any reference to x or y will be treated as a volatile read in the member function. Moreover, a volatile object can only call volatile member functions. … Read more

Does “volatile” guarantee anything at all in portable C code for multi-core systems?

I’m no expert, but cppreference.com has what appears to me to be some pretty good information on volatile. Here’s the gist of it: Every access (both read and write) made through an lvalue expression of volatile-qualified type is considered an observable side effect for the purpose of optimization and is evaluated strictly according to the … Read more

How do I specify the equivalent of volatile in VB.net?

There’s no equivalent of C#’s volatile keyword in VB.NET. Instead what’s often recommended is the use of MemoryBarrier. Helper methods could also be written: Function VolatileRead(Of T)(ByRef Address As T) As T VolatileRead = Address Threading.Thread.MemoryBarrier() End Function Sub VolatileWrite(Of T)(ByRef Address As T, ByVal Value As T) Threading.Thread.MemoryBarrier() Address = Value End Sub Also … Read more

What Rules does compiler have to follow when dealing with volatile memory locations?

What you know is false. Volatile is not used to synchronize memory access between threads, apply any kind of memory fences, or anything of the sort. Operations on volatile memory are not atomic, and they are not guaranteed to be in any particular order. volatile is one of the most misunderstood facilities in the entire … Read more

C/C++: casting away volatile considered harmful?

If the variable is declared volatile then it is undefined behaviour to cast away the volatile, just as it is undefined behaviour to cast away the const from a variable declared const. See Annex J.2 of the C Standard: The behavior is undefined in the following circumstances: … — An attempt is made to modify … Read more