RealTime Embedded Multithreading Using Thread X and ARM
Real-Time Embedded Multithreading, Using Thread. X and ARM ~ Chapter 10 ~ 學生 : 曾楓喬 指導教授 : 張軒彬
Outline n n n n Introduction Counting Semaphore Control Block Summary of Counting Semaphore Services Avoiding two things Comparing a Counting Semaphore with a Mutex Sample System Using a Binary Semaphore in Place of a Mutex Sample System Using a Counting Semaphore in a Producer-Consumer Application Counting Semaphore Internals
Introduction n n Thread. X provides 32 -bit counting semaphores with counts that range in value from 0 to 232 -1. An instance of a counting semaphore is a single count. Counting semaphores that have values restricted to 0 or 1 are called binary semaphores. An application may use an unlimited number of counting semaphores.
Counting Semaphore Control Block n n The characteristics of each counting semaphores are found in its Control Block. The Control Block can be located anywhere in memory.
Summary of Counting Semaphore Services
Creating a Counting Semaphore n n tx_semaphore_create Fig 10. 3 Counting semaphore attributes Counting Semaphore Control Block Counting semaphore name Initial count n The value for the count must be in the range from 0 x 0000 to 0 x. FFFF.
Creating a Counting Semaphore(cont. )
Getting an Instance of a Counting Semaphore n n tx_semaphore_get input parameters n n n semaphore_ptr wait_option The service retrieves an instance from the counting semaphore by decrementing its count.
Getting an Instance of a Counting Semaphore(cont. )
Getting an Instance of a Counting Semaphore(cont. )
Placing an Instance in a Counting Semaphore n n tx_semaphore_put input parameter n n semaphore_ptr The service places an instance in a counting semaphore by incrementing its count.
Placing an Instance in a Counting Semaphore(cont. )
Deleting a Counting Semaphore n n tx_semaphore_delete input parameter n n semaphore_ptr The service to delete a counting semaphore.
Deleting a Counting Semaphore(cont. )
Prioriting a Counting Semaphore Suspension List n n tx_semaphore_prioritize input parameter n n n semaphore_ptr The service places the highest-priority thread suspended on a specific counting semaphore at the front of the suspension list. All other threads remain in the same FIFO order in which they were suspended.
Prioriting a Counting Semaphore Suspension List(cont. )
Prioriting a Counting Semaphore Suspension List(cont. ) n n n Priority order : speedy > slow > min Enter order : min -> slow -> speedy After prioritizing : speedy-> min-> slow
Retrieving Information About a Counting Semaphore n n tx_semaphore_info_get input parameter semaphore_ptr n output parameters name current_value first_suspended_count next_semaphore n The service retrieves several useful pieces of information about a counting semaphore.
Retrieving Information About a Counting Semaphore(cont. )
Avoiding two things n There are two dangerous pitfalls associated in using semaphores for mutual exclusion. n n Avoiding deadly embrace Avoiding priority inversion
Comparing a Counting Semaphore with a Mutex
Sample System Using a Binary Semaphore in Place of a Mutex
Sample System Using a Binary Semaphore in Place of a Mutex(cont. )
Sample System Using a Binary Semaphore in Place of a Mutex(cont. )
Sample System Using a Binary Semaphore in Place of a Mutex(cont. )
Sample System Using a Binary Semaphore in Place of a Mutex(cont. )
Sample System Using a Binary Semaphore in Place of a Mutex(cont. )
Sample System Using a Counting Semaphore in a Producer-Consumer Application
Sample System Using a Counting Semaphore in a Producer-Consumer Application (cont. )
Sample System Using a Counting Semaphore in a Producer-Consumer Application (cont. )
Sample System Using a Counting Semaphore in a Producer-Consumer Application (cont. )
Sample System Using a Counting Semaphore in a Producer-Consumer Application (cont. )
Sample System Using a Counting Semaphore in a Producer-Consumer Application (cont. )
Counting Semaphore Internals
- Slides: 34