嵌入式導論實驗報告
Introduction to Embedded Systems
Exercise 3 Resource sharing
Ex 3.1
1.Explain the difference between private, shared and exclusive resources and give an example of problems encountered in exclusive resources.
Private resources are used exclusively by one process/thread,whereas shared resources can be used by at least two possibly competing process/thread.
Simultaneous use of a resource by multiple process/threads without further countermeasures,for example,can raise inconsistencies or illegible spending on printer or monitor. Such resources are also called exclusive resources,there really should always just one process/thread exclusively take on it.
答:私有資源由一個進程/線程獨占使用,而共享資源可以由至少兩個可能競爭的進程/線程使用。
例如,在沒有采取進一步措施的情況下,通過多個進程/線程同時使用資源可能會引起打印機或顯示器上的不一致或不明確。
這樣的資源分配方式也被稱為獨占資源,實際上應該總是只有一個進程/線程獨占。只是由于虛擬化的技術,資源在肉眼不可發現的情況下供各個進程/線程輪流使用。
2.Propose three ways such that the problem occurring in Resource Sharing Problem of mutual exclusion (mutual exclusion) can be solved.
Non-preemptive tasks,interrupts disabled,static scheduling,Use of semaphores.
解決方法:非搶先任務,禁用中斷,靜態調度,使用信號量。
3.Explain the application of a possible solution of the previous part.
A(binary)semaphore S is a data structure that can be accessed only by the
atomic commands,wait(s),bzw. P(s) and signals (s), bzw. V(S).
Assume a process A want to enter critical section,it executes a wait(s) on the semaphore and claims the right to entry into the critical section. If the process hears that the semaphore is free,he enters the critical section and releases the semaphore with signal(s) after he left its critical section. If the call of the semaphore wait(s) is occupied by another process B,A waits until B releases the semaphore.
(二進制)信號量S是一個數據結構,只能由原子命令P(s)V(s)操作。
假定一個進程A想要進入臨界區,它會在信號量上執行一個等待并聲明進入臨界區的權利。
如果進程聽到信號量是空閑的,他將進入臨界區,并在離開臨界區后用信號釋放信號量。
如果信號量等待的調用被另一個進程B占用,則A等待B釋放信號量。
信號量S是一個整數,S大于等于零是代表可供并發進程使用的資源實體數,當S小于零時則表示正在等待使用臨界區的進程數。
信號量操作的PV原語是:
P原語操作的動作是:
(1)S減1;
(2)若S減1后仍大于或等于零,則進程繼續執行;
(3)若S減1后小于零,則該進程被阻塞后進入與該信號相對應的隊列中,然后轉進程調度。
V原語操作的動作是:
(1)S加1;
(2)若相加結果大于零,則進程繼續執行;
(3)若相加結果小于或等于零,則從該信號的等待隊列中喚醒一等待進程,然后再返回原進程繼續執行或轉進程調度。
PV操作對于每一個進程來說,都只能進行一次,而且必須成對使用。在PV原語執行期間不允許有中斷的發生。
信號量機制分 整型信號量機制、記錄型信號量機制、and型信號量機制、信號量集。
整型信號量是一種最簡單的信號量,主要用于解決并發程序互斥訪問臨界資源問題。
Ex 3.2
4.In the lecture you learned about the Priority Inheritance Protocol (PIP). Does the PIP solve the problem of deadlocks? Give a brief explanation for your response.
No, the PIP does not prevent deadlocks.
答:不能,PIP不能防止死鎖。
PIP優先級繼承協議(Priority Inheritance Protocol,
PIP)的基本思想是當更高優先級的進程Ji被進程Jk阻塞時,Jk暫時繼承Ji的優先級,這將防止中間優先級的進程搶占進程Jk使高優先級進程Ji的阻塞時間延長。
PIP優先級繼承協議中的死鎖問題:
低優先級作業Jl獲取信號量S1進入臨界區Z1,在執行過程中高優先級Jh搶占Jl并獲取信號量S2進入臨界區Z2,在Z2中Jh申請S1被Jl阻塞,Jl繼承Jh優先級繼續執行Z1,此時Jl需要獲取S2,死鎖產生。
5.Given are the four tasks J1, J2, J3 and J4. The table below contains
information on their arrival times, deadlines, their execution time and priorities. The tasks with fixed priorities should be handled by a fixed priority scheduling processor as far as possible within their deadlines.
The drawings in the last row of the table provide information about the
sequence of individual tasks. Each task contains one or more critical sections, in which the system accesses the two exclusive resources A and B, respectively. In the drawings, each block has one unit of length and non-critical sections are shaded. The critical sections are marked with the corresponding letters A and B. For example, the seven time units long task J4 contains two critical sections, the five time periods long section A and the three time units long section B. A and B are nested here, i.e. during the periods 3-5 J4 must have access to both resource A and resource B.
Task:
Now create a scheduling with the Priority Inheritance Protocol and fill out the chart prepared below. Highlight the critical Portions of the tasks with the letters A and B as specified in the last line of the table . Please also
characterized p4 which is the active priority of Task J4 in the
given diagram. Note: Pay close attention to the priorities of the individual
tasks!
6.Are all deadlines satisfied through the application of the PIP? If not, how big is the maximum delay (maximum lateness) in units
of time?
No,J2 violated its deadline by two time units.
答:不滿足,J2違反兩個時間單位的最后期限。
- Is there a schedule for the tasks specified J1 to J4 that meets all
deadlines? What changes should be made to the priority? If there is a correct schedule, please show it in the graph provided below. Otherwise, explain why there can be no correct schedule.
Yes,there is a flow chart such that all deadlines can be met. However,one have to change the priority of at least one task. If PIP is to meet all
deadlines,for example,the priority order J4>J1>J2>J3 is a good choice.
是的,有一個流程圖,可以滿足所有的最后期限。
但是,必須改變至少一個任務的優先級。
如果PIP要滿足所有最后期限,例如,優先順序J4\> J1\> J2\> J3是一個不錯的選擇。