Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.66 KB

c28112.md

File metadata and controls

42 lines (30 loc) · 1.66 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C28112
Warning C28112
08/25/2022
C28112
INTERLOCKED_ACCESS
__WARNING_INTERLOCKED_ACCESS
C28112
2720a5dc-84e9-4f78-a8c7-a320c9f9216b

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)