Real-Time Embedded Multithreading: Using ThreadX and ARM

On many occasions, we need to guarantee that a thread has exclusive access to a shared resource or to a critical section. However, several threads may need to obtain these items, so we need to synchronize their behavior to ensure that exclusive access can be provided. In this chapter, we consider the properties of the mutex, which is designed solely to provide mutual exclusion protection by avoiding conflict between threads and preventing unwanted interactions between threads.
A mutex is a public resource that can be owned by, at most, one thread at any point in time. Furthermore, a thread (and only that same thread) can repeatedly [30] obtain the same mutex, 2 32 1 times to be exact. However, that same thread (and only that thread) must give up that mutex the same number of times before the mutex becomes available again.
[30]Some writers describe this type of mutex as a recursive mutex because of the same-thread, multiple ownership capability. However, we will not use that terminology here.
A critical section is a code segment in which instructions must be executed in sequence without interruption. The mutex helps in achieving this goal. Consider Figure 7.1, which shows a code segment that is a critical section. To enter this critical section, a thread must first obtain ownership of a certain mutex that protects the critical section. Thus, when the thread is ready to begin executing this code segment, it first attempts...