Back during the summer, atomic variables have been added to the kernel. These atomics are based upon the C++11 standard. lwn provides some background information. The article also references memory barriers which goes into great detail on how atomics work in terms of allowing code to sanely control the interaction of multiple CPU and devices. Another article provides more depth regarding C11 atomic variables and the kernel.
In C++, the standard library offers similar constructs with the Standard Atomic Operations Library, with descriptions of the Memory Order operations.
A blog entry from 2012 loose comparison: Comparing the performance of atomic, spinlock and mutex.
Boost based examples for atomics, with a sample spinlock, a singleton with double-checked locking pattern, wait free ring buffer, and wait free multi-producer queue.
On the side: Does a multiple producer single consumer lock-free queue exist for c++?.