Variables of lockable functions should be declared as mutable in source C ++

Is there a difference between:

    __declspec(align(8)) long long variable1; //assume shared among threads
    InterlockedIncrement64(&variable1);

And this:

    __declspec(align(8)) long long volatile variable2;//assume shared among threads
    InterlockedIncrement64(&variable2);

I assume that they will work exactly the same in this scenario. I think the only difference would be that if it variable1is available without a locked function, it is not guaranteed as the current value, but is variable2guaranteed to be the current value. Example:

long long x = variable1; //Not guaranteed to be the most recent value when accessed
long long y = variable2; //Guaranteed to be the most recent value when accessed

Am I correct in my assumptions? Note. I am using / volatile: ms compiler option in visual studio

+4
source share

Source: https://habr.com/ru/post/1650756/


All Articles