Can volatile variables be read multiple times between sequence points?

Reading the (ISO 9899:2018) standard literally, then it is undefined behavior. C17 5.1.2.3/2 – definition of side effects: Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects C17 6.5/2 – sequencing of operands: If a side effect on a scalar … Read more

Volatile Struct Semantics

In your example, the two are the same. But the issues revolve around pointers. First off, volatile uint8_t *foo; tells the compiler the memory being pointed to is volatile. If you want to mark the pointer itself as volatile, you would need to do uint8_t * volatile foo; And that is where you get to … Read more

What is the purpose of the “volatile” keyword appearing inside an array subscript?

The volatile keyword is used to declare an array type of a function parameter. Here, double x[volatile] is equivalent to double * volatile x. The cppreference says : In a function declaration, the keyword volatile may appear inside the square brackets that are used to declare an array type of a function parameter. It qualifies … Read more

Are volatile variable ‘reads’ as fast as normal reads?

You should really check out this article: http://brooker.co.za/blog/2012/09/10/volatile.html. The blog article argues volatile reads can be a lot slower (also for x86) than non-volatile reads on x86. Test 1 is a parallel read and write to a non-volatile variable. There is no visibility mechanism and the results of the reads are potentially stale. Test 2 … Read more

What is the point of making the singleton instance volatile while using double lock? [duplicate]

The volatile prevents memory writes from being re-ordered, making it impossible for other threads to read uninitialized fields of your singleton through the singleton’s pointer. Consider this situation: thread A discovers that uniqueInstance == null, locks, confirms that it’s still null, and calls singleton’s constructor. The constructor makes a write into member XYZ inside Singleton, … Read more

Why not volatile on System.Double and System.Long?

He’s implying that a processor-specific detail should not show up to a person using a framework that “abstracts” details like that away from the programmer. If you are using low-lock techniques like volatile fields, explicit memory barriers, and the like, then you are entirely in the world of processor-specific details. You need to understand at … Read more

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

How to cast away the volatile-ness?

Use const_cast. For example, volatile sample *pvs = new sample(); sample *ps = const_cast<sample*>(pvs); //casting away the volatile-ness That is, const_cast is used to cast away both const-ness as well as volatile-ness. Unfortunately, its name doesn’t contain the term “volatile”. Maybe, that is because the keyword const is more common in use than the keyword … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)