Critical sections, exclusive execution, and atomicity
Imagine you’re writing software for a multicore system (well, nowadays, it’s typical that you will work on multicore systems, even on most embedded projects). As we mentioned in the introduction, running multiple code paths in parallel is not only safe but also desirable (why spend those dollars otherwise, right?). On the other hand, concurrent (parallel and simultaneous) code paths within which shared writable data (also known as shared state) is accessed in any manner is where you are required to guarantee that, at any given point in time, only one thread can work on that data at a time! This is key. Why? Think about it: if you allow multiple concurrent code paths to work in parallel on shared writable data, you’re asking for trouble: data corruption (a “data race”) can occur as a result. The following section, after covering some key points, will clearly illustrate the data race concept with...