assuming there is a class to control concurrent access to a (critical) block of code like this:
class RAIIObj : public boost::noncopyable {
public:
explicit RAIIObj( LockObj& Obj ) : LkObj( Obj ) { Obj.Acquire(); }
~RAIIObj() { try { Obj.Release(); } catch (...) {} }
private:
LockObj& LkObj;
};
When using this part of the code, do I need to use the volatile keyword to order not to see the code optimized?
For example, I need to write
ALockingObj LockObj;
void AFunc() {
RAIIObj LKGuard( LockObj );
}
or
ALockingObj LockObj;
void AFunc() {
volatile RAIIObj LKGuard( LockObj );
}
to make sure LKGuard always exists?
Since LKGuard is a local variable that is not used at any point in the body of the function, can it be optimized if I do not use the volatile keyword?
thank
source
share