LIVE Course for free

Rated by 1 million+ students
Get app now
JEE MAIN 2025 Foundation Course
NEET 2024 Crash Course
NEET 2025 Foundation Course
0 votes
in Computer by (30.0k points)
closed by

Consider the following proposed solution for the critical section problem. There are n processes: P0…Pn – 1. In the code, function pmax returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero.

Code for Pi:

do {

                c [i]=1; t[i] = pmax (t [0],…, t[n-1]) +1; c[i]=0;

                for every j ≠ I in {0,…,n-1} {

                                while (c[j]);

                                while (t[j] != 0 && t[j]<=t[i]) ;


                Critical section;

                t[i] =0;

                Remainder Section;

} While (true);

Which one of the following is TRUE about the above solution?
1. At most one process can be in the critical section at any time
2. The bounded wait condition is satisfied
3. The progress condition is satisfied
4. It cannot cause a deadlock

1 Answer

0 votes
by (48.1k points)
selected by
Best answer
Correct Answer - Option 1 : At most one process can be in the critical section at any time

Given code is a N process synchronization solution (known as Lamport’s bakery algorithm)

; c[i]=0;

This helps in getting the token. Each process which wants to enter into critical section, gets a token number (as in a restaurant) and wait for his turn.

c[i]=1 //announce that process Pi is ready to take it’s token number

t[i] = pmax (t [0],…, t[n-1]) +1 //get token number

c[i]=0; // means process Pi has taken it’s token number

As more than one process can get same token value and then suppose P2 wants to enter the critical section. So, this line will be executed

while (t[j] != 0 && t[j]<=t[i]) ;

Now, j!=i, P2 scans for other processes and check if anyone of them have it’s token value less than or equal to it’s own token value. When P2 finds true then it starts looping at the condition. Similar for other processes. So, when P1 ­finds that all other processes have their token value as non zero and have value less than token of P1. It also waits. It becomes the situation of deadlock.

When deadlock in the system, progress will not be satisfied here.

Also, when a process reaches critical section, all other processes which started before it must have its token value as 0. This means that no two processes can be in critical section at the same time.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.