Warning C28112

A variable (parameter-name) which is accessed via an Interlocked function must always be accessed via an Interlocked function. See line line-number: It is not always safe to access a variable which is accessed via the Interlocked* family of functions in any other way.

A variable that is accessed by using the Interlocked executive support routines, such as InterlockedCompareExchangeAcquire, is later accessed by using a different function.

Remarks

InterlockedXxx functions are intended to provide atomic operations, but are only atomic with respect to other InterlockedXxx functions. Although certain ordinary assignments, accesses, and comparisons to variables that are used by the Interlocked* routines can be safely accessed by using a different function, the risk is great enough to justify examining each instance.

Code analysis name: INTERLOCKED_ACCESS

Example

The following code generates this warning:

inter_var--;
//code
InterlockedIncrement(&inter_var);

The following code corrects this warning by strictly accessing inter_var through InterlockedXxx functions:

InterlockedDecrement(&inter_var);
//code
InterlockedIncrement(&inter_var);

See Also

InterlockedIncrement function (wdm.h)
InterlockedDecrement function (wdm.h)