Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7 Real-Time Embedded Multithreading Mutual Exclusion Challenges and Considerations.

Similar presentations


Presentation on theme: "Chapter 7 Real-Time Embedded Multithreading Mutual Exclusion Challenges and Considerations."— Presentation transcript:

1 Chapter 7 Real-Time Embedded Multithreading Mutual Exclusion Challenges and Considerations

2 OUTLINE Introduction Protecting a critical Section Providing Exclusive Access to Shared Resources Mutex Control Block Summary of Mutex Services Avoiding the Deadly Embrace Sample System Using a Mutex to Protect Critical Sections Mutex Internals

3 Introduction To guarantee that a thread has exclusive a access to a shared resource or to a critical section Ensure that exclusive access can be provided A mutex is a public resource that can be owned by, at most, one thread at any point in time.

4 Protecting a Critical Section (CONT.) A critical section is a code segment in which instructions must be executed in sequence without interruption. To enter this critical section, a thread must first obtain ownership of a certain mutex that protects the critical section.

5 Protecting a Critical Section

6 Providing Exclusive Access to Shared resources (CONT.) A mutex can provide exclusive access to one shared resource in the same manner that it can protect a critical section. If a thread must have exclusive access to two (or more) shared resources at the same time, then it must protect each shared resource with a separate mutex.

7 Providing Exclusive Access to Shared resources

8 Mutex Control Block (CONT.) The mutex control block (MCB) is a structure used to maintain the state of a mutex during run-time.

9 Mutex Control Block

10 Summary of Mutex Services (CONT.) Creating a Mutex A mutex is declared with the TX_MUTEX data type and is defined with the tx_mutex_create service. Priority inheritance allows a lower-priority thread to temporarily assume the priority of a higher-priority thread that is waiting for a mutex owned by the lower-priority thread

11 Summary of Mutex Services (CONT.)

12 Deleting a Mutex Delete a mutex When a mutex is deleted, all thread that have been suspended because they are waiting for that mutex are resumed.

13 Summary of Mutex Services (CONT.) Speedy 5, 5 Slow 5,5

14 Summary of Mutex Services (CONT.)

15

16 Obtaining Ownership of a Mutex Attempt to obtain ownership of a mutex If you use priority inheritance, make certain that you do not allow external thread to modify the priority of the thread that has inherited a higher priority during mutex ownership.

17 Summary of Mutex Services (CONT.)

18 Slow 10,10 Speedy 5,5 TX_INHE RIT

19 Summary of Mutex Services (CONT.)

20

21 Speedy 5,5 Slow 10,10 Third 10,10

22 Summary of Mutex Services (CONT.)

23

24

25 Retrieving mutex Information Retrieve information about a mutex

26

27 Summary of Mutex Services (CONT.)

28 Prioritizing the Mutex Suspension List Put highest-priority suspended thread at front of suspension list

29 Summary of Mutex Services Releasing Ownership of a Mutex Release ownership of mutex If the ownership count become zero, the mutex becomes available. If the mutex becomes available and if priority inheritance is enabled for this mutex, then the priority of the releasing thread reverts to the priority it had when it originally obtained ownership of the mutex.

30 Avoiding the Deadly Embrace (CONT.) Permit a thread to own at most one mutex at any time. If thread must own multiple mutexes, you can generally avoid deadly embraces if you make the thread gather the mutexes in the same order.

31 Avoiding the Deadly Embrace (CONT.) One way to recover from a deadly embrace is to use the suspension time-out feature associated with the tx_mutex_get service. Another way to recover from a deadly embrace is for another to invoke the tx_thread_wait_abort service to abort the suspension of a thread trapped in a deadly embrace

32

33 Sample System using a Mutex to Protect Critical Sections (CONT.)

34

35 Sample System using a Mutex to Protect Critical Sections

36 Mutex Internals


Download ppt "Chapter 7 Real-Time Embedded Multithreading Mutual Exclusion Challenges and Considerations."

Similar presentations


Ads by Google