(a) Consider the following three tasks, which use the shared variables x and z,
ID: 3807106 • Letter: #
Question
(a) Consider the following three tasks, which use the shared variables x and z, guarded by the semaphores Sx and Sz, respectively. Assume that the tasks are numbered in order of decreasing priority: Task 1 has the highest priority, and Task 3 the lowest. These tasks each contain the following lines of code: What problem or problems do you see with the use of semaphores in these tasks? (b) Does priority inheritance solve the problems you noted in part la? If so, explain how. If not, propose an alternate solution.Explanation / Answer
Suppose there are three tasks Task1, Task2 and T3 are arranged in decreasing order of priority.
Task1- Highest
Task2- Medium
Task3- Lowest
During the execution of the critical section of task T3, high-priority task T1 starts to execute, Task3, and later attempts to use the shared data.
Task1 is blocked on the semaphore S 1. We will give prefer that Task1, being the highest priority task, be blocked no longer than the time it takes for Task3 to complete its critical section.
However, the duration of blocking is, in fact, unpredictable. This is because Task3 can be preempted by the medium priority task Task2. Task1 will be blocked, that is, prevented from executing, until Task2 and any other pending tasks of intermediate priority are completed.
So, as per your given examples, we will face these types of problem in semaphore in these tasks.
So, we can say that this solution is only true for very short critical sections because it creates unnecessary priority inversion. For instance, once a low-priority job enters a long critical section, a high priority job that does not access the shared data structure may be needlessly blocked.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.