Locking – a quick summarization of key points
As mentioned just above, do refer to the Linux Kernel Programming – Part 2 book to brush up on the basics of locking within the Linux kernel (if you need to) – more importantly, on kernel-level debug techniques as well as guidelines on preventing and detecting dangerous locking bugs such as the deadly deadlock.
Nevertheless, I'd like to summarize some really key points with respect to locking here as well. Here they are:
- A critical section is a code path that can execute in parallel and that works on (reads and/or writes) shared writeable data (also known as shared state).
- Because it works on shared writable data, the critical section requires protection from the following:
- Parallelism (that is, it must run alone, serialized, in a mutually exclusive fashion)
- When running in an atomic (for example, interrupt) non-blocking context, it must run atomically: indivisibly, to completion, without interruption...