Compare the benefits of Peterson\'s solution to the mutual exclusion problem as
ID: 3833974 • Letter: C
Question
Compare the benefits of Peterson's solution to the mutual exclusion problem as against solutions using semaphores. Explain what the priority inversion problem is. Suggest a way in which modern operating systems can handle it. (c) The exchange machine instruction is defined as follows: void exchange (int register, int memory) {int temp; temp = memory; memory = register; register = temp;} It is assumed that it is implemented as an atomic instruction. Describe how exchange can be used to achieve mutual exclusion for n processes (e.g. by writing a mutual exclusion procedure using pseudo-code). Explain whether your solution avoids busy waiting.Explanation / Answer
5. a) Peterson's algorithm (or Peterson's solution) is a concurrent programming algorithm for mutual exclusion that allows two or more processes to share a single-use resource without conflict, using only shared memory for communication. If we given 2 process i and j, and needed to write a program that can guarantee mutual exclusion between the two without any additional hardware support Peterson's algorithm is best suited for it rather than semaphores as it is the simplest known solution to the mutual exclusion problem for the special case of two process.
Semaphore concept occured with multiple process where lock mechanism comes into picture. The main advantage of using Peterson's solution to the mutula exclusion is:
In Peterson's algorithm, a process will never wait longer than one turn for entrance to the critical section: After giving priority to the other process, this process will run to completion and set its flag to 1, thereby never allowing the other process to enter the critical section.
b) Priority inversion is a problem in scheduling. It changes the priorities between high priority task and low priority task by inverting their priorities. The modern operating systems are designed in such a way that it is designed to have the low-priority threads temporarily inherit the high priority of everyone who is waiting on locks they hold. This is known as priority inheritance.
c)The exchange machine instruction is defined as follows:
void exchange (int register, int memory)
{
int temp;
temp = memory;
memory = register;
register = temp;
}
When implementing the mutual exclusion mechanism, a shared variable, bolt, is set to 0. Each process uses a local variable key, initialized to 1. The only process that is allowed to enter its critical section is the one that finds bolt equal to 0. This process then excludes other processes by setting bolt to 1, the value of its local variable keyi. When a process exits from its critical section, it resets bolt back to 0, which is then used to activate the next looping process.
Given is the mutual exclusion procedure
int const n=/*number of processes*/;
int bolt;
void P(int i){
int keyi=1;
while(true){
keyi=1;
do exchange(keyi, bolt)
while(keyi!=0);
/*critical section*/;
exchange(keyi, bolt);
/*remainder*/;
}
}
void main(){
bolt=0;
parbegin(P(1), P(2), ..., P(n));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.