Critical sections, exclusive execution, and atomicityWhat is a critical section?A classic case – the global i ++Concepts – the lockA summary of key pointsConcurrency concerns within the Linux kernelMulticore SMP systems and data racesPreemptible kernels, blocking I/O, and data racesHardware interrupts and data racesLocking guidelines and deadlocksMutex or spinlock? Which to use whenDetermining which lock to use – in theoryDetermining which lock to use – in practiceUsing the mutex lockInitializing the mutex lockCorrectly using the mutex lockMutex lock and unlock APIs and their usageMutex lock – via [un]interruptible sleep?Mutex locking – an example driverThe mutex lock – a few remaining pointsMutex lock API variantsThe mutex trylock variantThe mutex interruptible and killable variantsThe mutex io variantThe semaphore and the mutexPriority inversion and the RT-mutexInternal designUsing the spinlockSpinlock – simple usageSpinlock – an example driverTest – sleep in an atomic contextTesting on a 5.4 debug kernelTesting on a 5.4 non-debug distro kernelLocking and interruptsUsing spinlocks – a quick summarySummaryQuestionsFurther reading