In principle, all of these InterlockedXXX functions are more or less internal, which are compared with relatively small (usually one) assembly instructions. Such an operation cannot be interrupted and, therefore, is considered atomic (atomicity is achieved at the CPU level, at least if it is possible on the target platform).
A CRITICAL_SECTION is a synchronization primitive that can protect longer sections. In fact, locking and competing threads will have to wait until the thread releases ownership of the critical section.
Critical sections are OS primitives, but they are limited to one process. Their older brother in the critical section under Windows is Mutex , which can be used for the cross-synchronization process.
Use InterlockedXXX functions if you can (for example, it makes no sense to use the full critical section object to protect a single counter). You might want to take a look at the various prototypes and their use in advance. Many people use critical sections where InterlockedCompareExchange will be ...
source share