The following code fragment is a 2-process "solution" to the critical section problem
try [i] = true ;
while (incs[j]) no-op;
while (turn=j and try[j]) no-op;
incs [i] = true ;
critical section
try [i] = false;
incs [i] = false;
turn = j ;
Does the above "solution" meet all 3 conditions of critical sections? Please explain your answer.
Yes,
For process table:
repeat
………………….
critical section
……………………
remainder section
until FALSE
We have, Solution to the Critical Section Problem must meet three conditions defined below:
In ques,
In second line,
While (incs[j]) no-op :It is saying that while process ‘I’ is in critical section, no other process is allowed to enter into it. That is meeting out first condition of Mutual exclusion.
Lines,
Try[i]=False
Incs[i]=False
Turn j
It is an example of progress, i.e. Process ‘j’ was waiting earlier when process ‘I’ was in critical section ,now when ‘I ‘ is not in critical section ,waiting process ‘j’ is allowed to enter into the critical section.
Also ,it is na example of Bounded waiting i.e. once a process enters its critical section, it does not get another turn until a waiting process gets a turn (managed as a queue)
Thanks !
The following code fragment is a 2-process "solution" to the critical section problem try ] =...
a. Given the solution for the critical section problem for two processes (the code shown is for processes Pi), show why it does not satisfy the mutual exclusion requirement. Here, lock is a shared variable initialized to FALSE. (Hint: Indicate one scenario where the mutual exclusion requirement is violated.): do { while (lock); lock=TRUE Critical section lock=FALSE; Remainder section } b. What happens if lock is initialized to TRUE in the code above?
a)Given the following solution for the critical section problem for two processes (the code shown is for processes Pi), show why it does not satisfy the mutual exclusion requirement. Here,lock is a shared variable initialized to FALSE. (Hint: Indicate one scenario where the mutual exclusion requirement is violated.) do { lock = FALSE; while (lock); lock = TRUE Critical section /Empty section Remainder section } (b)Does this satisfy the progress requirement? Justify your answer
Following is the hardware TestAndSet solution for critical-section problem. Can this solution satisfy bounded waiting? Explain your answer. Shared boolean variable: lock (initialized to false) Solution: while (true) { while(TestAndSet(&lock)) ; /*do nothing //critical section lock = FALSE; //remainder section }
I undertand the algo is Peterson's Solution and that it will not cause deadlocks or busy waiting. But does this solve the critical section problem in its entirety such as in the case of more than 2 processes. Does this Scanned Documents 1.jpg w the following code. What algorithm does this implement? solve the critical section problem, defend your decision, explain in detail Revi #define FALSE O #define TRUE 1 /*number of processes / #define N 2 int turn int...
Given two processes, the structure of each process is as follows: do f flag [i] -ture ; while (flag [j] “ turn-j); //Critical Section flag[i]false; //Remainder Section while (1) Determine whether it is a correct solution to the critical-section problem. If yes, prove that the algorithm satisfies requirements for the critical-section problem. If' not, explain your answer
What are the three requirements for a solution to the critical-section problem? Consider the following solution to the dining-philosophers' problem. // Global variables. Shared among threads int state [5]; semaphore mutex; I/ Initially set to 1 semaphore s [5] I Initially s[i] is set to 0 for all i Initially statei]-THINKING for all i void philosopher (int i) f int left(int i) f // Philosopher to the left of i // % is the mod operator. while(TRUE) thinkO take.forks ()...
Code fragment 2: template <class T> Tplus slancio, T12) ( Tret: Tet - ol +12 Tetun Tet; } Code fragment 3: Problem 1 (10 points)-True/False Submit a document called Answers.doc Answer the following true/false questions. You must correctly state WIIY your answer is true or false in order to receive credit class Popcorn std::string flavor protected: float price Code fragment 1: public class Employee friend class Movie_gcer Popcorn slumstring Daver, float price) public: static int total employees; int employee_id; this...
Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32) num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test { ...
problem 1: Calculate the [H3O+] of a solution with pH of 4.20. problem 2: True or False, The acidity of Al (H2O)6 derives from the positively charged aluminum ion which draws electrons from the oxygen atoms, in turn, weakening the O-H bond. please answer both and explain, I'm having a hard time with acidity, will rate
2. What is the output of the following code fragment? n = 1; while (n <= 5) { n++; cout << n << ' '; a.1 2 3 4 5 b. 1 2 3 4 c. 1 1 1 forever d. 2 3 4 5 e. 2 3 4 5 6 3. What is the termination condition for the following While loop? while (beta > 0 && beta < 10) { cout << beta << endl; cin >> beta; }...