Edit

Share via


Warning C28113

Accessing a local variable via an Interlocked function

The driver is using an Interlocked executive support routine, such as InterlockedDecrement, to access a local variable.

Although drivers are permitted to pass the address of a local variable to another function, and then use an interlocked function to operate on that variable, it's important to verify that the stack won't be swapped out to disk unexpectedly and that the variable has the correct life time across all threads that might use it.

Example

Typically, the return value of an Interlocked executive support routine is used in subsequent computations, instead of the input arguments. Also, the Interlocked routines only protect the first (leftmost) argument. Using an Interlocked routine in the following way doesn't protect the value of global and often serves no purpose.

InterlockedExchange(&local, global)

The following form has the same effect on the data and safely accesses the global variable.

local = InterllockedExchange(&global, global)