# Linux Kernel Module Cheat

#### 29.3.1. x86 exchange instructions

Intel 64 and IA-32 Architectures Software Developer’s Manuals Volume 1 7.3.1.2 "Exchange Instructions":

- userland/arch/x86_64/xadd.S XADD: exchange and add. This is how C `<atomic>`'s' `` is implemented in GCC 5.1. TODO: why is the exchange part needed?

- userland/arch/x86_64/xchg.S XCHG: exchange two values

TODO: concrete multi-thread GCC inline assembly examples of how all those instructions are normally used as synchronization primitives.

- x86 CMPXCHG instruction