Interlocked Functions

Interlocked functions synchronize access to a variable that is shared by multiple threads. Their purpose is to prevent a thread from being preempted when it is in the middle of incrementing or checking a variable. The threads of different processes can use these functions as long as their variables share memory. Windows CE supports three interlocked functions: InterlockedIncrement, InterlockedDecrement, and InterlockedExchange. The following table describes the tasks that you can perform with each function.

To
Call
Increment a shared variable and check the resulting value InterlockedIncrement
Decrement a shared variable and check the resulting value InterlockedDecrement
Exchange the values of specified variables InterlockedExchange
Exchange the values of specified variables only if one of the variables is equal to a specified value InterlockedTestExchange