real-time embedded multithreading, using threadx and arm ~ chapter10 ~ 學生 : 曾楓喬 學生 :...
Post on 22-Dec-2015
293 views
TRANSCRIPT
Real-Time EmbeddedReal-Time EmbeddedMultithreading, Using ThreaMultithreading, Using Threa
dX and ARMdX and ARM~ Chapter10 ~~ Chapter10 ~
學生 學生 : : 曾楓喬曾楓喬指導教授 指導教授 : : 張軒彬張軒彬
OutlineOutline IntroductionIntroduction Counting Semaphore Control BlockCounting Semaphore Control Block Summary of Counting Semaphore ServicesSummary of Counting Semaphore Services Avoiding two thingsAvoiding two things Comparing a Counting Semaphore with a MutexComparing a Counting Semaphore with a Mutex Sample System Using a Binary Semaphore in Place of a Sample System Using a Binary Semaphore in Place of a
MutexMutex Sample System Using a Counting Semaphore in a ProduSample System Using a Counting Semaphore in a Produ
cer-Consumer Applicationcer-Consumer Application Counting Semaphore InternalsCounting Semaphore Internals
IntroductionIntroduction
ThreadX provides 32-bit counting semaphores wiThreadX provides 32-bit counting semaphores with counts that range in value from 0 to 2th counts that range in value from 0 to 23232-1.-1.
An An instanceinstance of a counting semaphore is a single c of a counting semaphore is a single count.ount.
Counting semaphores that have values restricted tCounting semaphores that have values restricted to 0 or 1 are called o 0 or 1 are called binary semaphoresbinary semaphores..
An application may use an unlimited number of cAn application may use an unlimited number of counting semaphores. ounting semaphores.
Counting Semaphore Control BlockCounting Semaphore Control Block
The characteristics of each counting semaphores are The characteristics of each counting semaphores are found in its Control Block. found in its Control Block.
The Control Block can be located anywhere in memThe Control Block can be located anywhere in memory.ory.
Summary of Counting Semaphore SSummary of Counting Semaphore Serviceservices
Creating a Counting Semaphore Creating a Counting Semaphore
tx_semaphore_createtx_semaphore_create Fig10.3 Counting semaphore attributesFig10.3 Counting semaphore attributes
The value for the count must be in the range frThe value for the count must be in the range from 0x00000000 to 0xFFFFFFFF.om 0x00000000 to 0xFFFFFFFF.
Counting Semaphore Control BlockCounting Semaphore Control Block
Counting semaphore nameCounting semaphore name
Initial countInitial count
Creating a Counting Semaphore(cont.)Creating a Counting Semaphore(cont.)
Getting an Instance of a Counting Getting an Instance of a Counting Semaphore Semaphore
tx_semaphore_gettx_semaphore_get input parametersinput parameters
semaphore_ptrsemaphore_ptr
wait_option wait_option The service retrieves an instance from the couThe service retrieves an instance from the cou
nting semaphore by decrementing its count.nting semaphore by decrementing its count.
Getting an Instance of a Counting SeGetting an Instance of a Counting Semaphore(cont.)maphore(cont.)
Getting an Instance of a Counting SeGetting an Instance of a Counting Semaphore(cont.)maphore(cont.)
Placing an Instance in a Counting SePlacing an Instance in a Counting Semaphoremaphore
tx_semaphore_puttx_semaphore_put input parameterinput parameter
semaphore_ptrsemaphore_ptr The service places an instance in a counting seThe service places an instance in a counting se
maphore by incrementing its count.maphore by incrementing its count.
Placing an Instance in a Counting SePlacing an Instance in a Counting Semaphore(cont.)maphore(cont.)
Deleting a Counting SemaphoreDeleting a Counting Semaphore
tx_semaphore_deletetx_semaphore_delete input parameterinput parameter
semaphore_ptrsemaphore_ptr The service to delete a counting semaphore.The service to delete a counting semaphore.
Deleting a Counting Semaphore(conDeleting a Counting Semaphore(cont.)t.)
Prioriting a Counting Semaphore SuPrioriting a Counting Semaphore Suspension Listspension List
tx_semaphore_prioritizetx_semaphore_prioritize input parameterinput parameter
semaphore_ptrsemaphore_ptr The service places the highest-priority thread sThe service places the highest-priority thread s
uspended on a specific counting semaphore at uspended on a specific counting semaphore at the front of the suspension list.the front of the suspension list.
All other threads remain in the same FIFO ordAll other threads remain in the same FIFO order in which they were suspended. er in which they were suspended.
Prioriting a Counting Semaphore SuPrioriting a Counting Semaphore Suspension List(cont.)spension List(cont.)
Prioriting a Counting Semaphore SuPrioriting a Counting Semaphore Suspension List(cont.)spension List(cont.)
Priority order : speedy > slow > minPriority order : speedy > slow > min Enter order : min -> slow -> speedyEnter order : min -> slow -> speedy After prioritizing : speedy-> min-> slowAfter prioritizing : speedy-> min-> slow
Retrieving Information About a CouRetrieving Information About a Counting Semaphore nting Semaphore
tx_semaphore_info_gettx_semaphore_info_get input parameterinput parameter
semaphore_ptrsemaphore_ptr output parametersoutput parameters
namenamecurrent_valuecurrent_valuefirst_suspendedfirst_suspendedsuspended_countsuspended_countnext_semaphorenext_semaphore
The service retrieves several useful pieces of informatThe service retrieves several useful pieces of information about a counting semaphore .ion about a counting semaphore .
Retrieving Information About a CouRetrieving Information About a Counting Semaphore(cont.)nting Semaphore(cont.)
Avoiding two thingsAvoiding two things
There are two dangerous pitfalls associated in There are two dangerous pitfalls associated in using semaphores for mutual exclusion.using semaphores for mutual exclusion.
Avoiding deadly embraceAvoiding deadly embrace
Avoiding priority inversionAvoiding priority inversion
Comparing a Counting Semaphore Comparing a Counting Semaphore with a Mutexwith a Mutex
Sample System Using a Binary SemaSample System Using a Binary Semaphore in Place of a Mutexphore in Place of a Mutex
Sample System Using a Binary SemaSample System Using a Binary Semaphore in Place of a Mutex(cont.)phore in Place of a Mutex(cont.)
Sample System Using a Binary SemaSample System Using a Binary Semaphore in Place of a Mutex(cont.)phore in Place of a Mutex(cont.)
Sample System Using a Binary SemaSample System Using a Binary Semaphore in Place of a Mutex(cont.)phore in Place of a Mutex(cont.)
Sample System Using a Binary SemaSample System Using a Binary Semaphore in Place of a Mutex(cont.)phore in Place of a Mutex(cont.)
Sample System Using a Binary SemaSample System Using a Binary Semaphore in Place of a Mutex(cont.)phore in Place of a Mutex(cont.)
Sample System Using a Counting SemapSample System Using a Counting Semaphore in a Producer-Consumer Applicatiohore in a Producer-Consumer Applicatio
nn
Sample System Using a Counting SemapSample System Using a Counting Semaphore in a Producer-Consumer Applicatiohore in a Producer-Consumer Applicatio
n (cont.)n (cont.)
Sample System Using a Counting SemapSample System Using a Counting Semaphore in a Producer-Consumer Applicatiohore in a Producer-Consumer Applicatio
n (cont.)n (cont.)
Sample System Using a Counting SemapSample System Using a Counting Semaphore in a Producer-Consumer Applicatiohore in a Producer-Consumer Applicatio
n (cont.)n (cont.)
Sample System Using a Counting SemapSample System Using a Counting Semaphore in a Producer-Consumer Applicatiohore in a Producer-Consumer Applicatio
n (cont.)n (cont.)
Sample System Using a Counting SemapSample System Using a Counting Semaphore in a Producer-Consumer Applicatiohore in a Producer-Consumer Applicatio
n (cont.)n (cont.)
Counting Semaphore InternalsCounting Semaphore Internals