tailieunhanh - Real-Time Embedded Multithreading Using ThreadX and MIPS- P6

Real-Time Embedded Multithreading Using ThreadX and MIPS- P6:Although the history of embedded systems is relatively short, 1 the advances and successes of this fi eld have been profound. Embedded systems are found in a vast array of applications such as consumer electronics, “ smart ” devices, communication equipment, automobiles, desktop computers, and medical equipment. | CHAPTER 8 Mutual Exclusion Challenges and Considerations Introduction 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 repeatedly1 obtain the same mutex 232-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. Protecting a Critical Section 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 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 to acquire that 1Some 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. cioHa oaLeHori tii Krxai LerHiaimi Please purchase PDF Split-Merge on . 100 Chapter 8 Thread Code segment Thread Figure Mutex protecting a critical section Figure Mutexes providing exclusive access to multiple shared resources mutex. After the thread has acquired the mutex it executes the code segment and then relinquishes the mutex. Providing Exclusive Access to Shared Resources A mutex can provide exclusive .