Locking – common mistakes and guidelines
To wrap up, a quick reference or summary, if you will, covering the typical common mistakes made when locking, and (with some repetition), locking guidelines. (Note that some of the techniques mentioned here – like lock-free programming – are covered in the following chapter).
Common mistakes
- Not recognizing critical sections:
- “Simple” increments/decrements (of the
i ++
ori --
type): As we learned in the A classic case – the global i ++ section, these too can be critical sections. In the following chapter, we show optimized and atomic ways to work with them. - “Hey, I’m only reading the shared data”: It’s still a critical section if the two conditions for one are met; not protecting it can result in a dirty or torn read, inconsistent or corrupted data.
- Deadlock: A situation where forward progress is impossible; carefully design...
- “Simple” increments/decrements (of the