Why ensuring mutual exclusion is important when accessing shared resources

A fundamental problem in multitasking is accessing shared resources. Text books often introduce this topic by considering the following problem. Imagine two tasks, both having access to a global variable. The job of one task, called an incrementer, is to increment the shared variable. The other task, called the decrementer, decrements the shared variable. The increment and decrement operations in each task are embedded within identical for loops. In this way, we arrange for the variable to be incremented and decremented the same number of times. The shared variable is reset to zero before the tasks are created and run. Once the tasks complete, one may expect the value of ...

Get ARM® Cortex® M4 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.