Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Barrier is a synchronization construct where ... Start Learning for Free
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.
void barrier (void) {
1: P(S);
2: process_arrived++;
3. V(S);
4: while (process_arrived !=3);
5: P(S);
6: process_left++;
7: if (process_left==3) {
8: process_arrived = 0;
9: process_left = 0;
10: }
11: V(S);
}
 
Q. The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?
  • a)
    The barrier implementation is wrong due to the use of binary semaphore S
  • b)
    The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.
  • c)
    Lines 6 to 10 need not be inside a critical section
  • d)
    The barrier implementation is correct if there are only two processes instead of three.
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Barrier is a synchronization construct where a set of processes synchr...
It is possible that process_arrived becomes greater than 3. It will not be possible for process arrived to become 3 again, hence deadlock.
View all questions of this test
Most Upvoted Answer
Barrier is a synchronization construct where a set of processes synchr...

Explanation:

Deadlock Possibility:
- The given barrier implementation may lead to a deadlock if two barrier invocations are used in immediate succession.
- This is because after the first barrier is completed, the value of process_left will be 3, and the next barrier invocation will not reset this value to 0, causing the while loop in line 4 to become an infinite loop.

Binary Semaphore:
- The issue is not with the use of the binary semaphore S, but with the logic of the barrier implementation.
- The binary semaphore is used for mutual exclusion to ensure only one process accesses the shared variables at a time.

Critical Section:
- Lines 6 to 10 should be inside a critical section to ensure that the shared variables process_left and process_arrived are updated atomically.
- Without a critical section, there could be race conditions leading to incorrect behavior of the barrier.

Correctness with Two Processes:
- The barrier implementation is incorrect regardless of the number of processes (two or three) due to the possibility of deadlock as explained above.
- Therefore, the correct answer is that the barrier implementation may lead to a deadlock if two barrier invocations are used in immediate succession.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer?
Question Description
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer?.
Solutions for Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.void barrier (void) {1: P(S);2: process_arrived++;3. V(S);4: while (process_arrived !=3);5: P(S);6: process_left++;7: if (process_left==3) {8: process_arrived = 0;9: process_left = 0;10: }11: V(S);}Q.The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?a)The barrier implementation is wrong due to the use of binary semaphore Sb)The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession.c)Lines 6 to 10 need not be inside a critical sectiond)The barrier implementation is correct if there are only two processes instead of three.Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev