Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The atomic fetch-and-set x, y instruction unc... Start Learning for Free
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .
void P (binary_semaphore *s) {
     unsigned y;
     unsigned *x = &(s->value);
     do {
           fetch-and-set x, y;
      } while (y);
}
void V (binary_semaphore *s) {
    S->value = 0;
}
 
Q. Which one of the following is true?
  • a)
    The implementation may not work if context switching is disabled in P.
  • b)
    Instead of using fetch-and-set, a pair of normal load/store can be used
  • c)
    The implementation of V is wrong
  • d)
    The code does not implement a binary semaphore
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
The atomic fetch-and-set x, y instruction unconditionally sets the mem...
Option (B) :- If we use normal load & Store instead of Fetch & Set there is good chance that more than one Process sees S.value as 0 & then mutual exclusion wont be satisfied. So this option is wrong.
Option (C) :- Here we are setting S->value to 0, which is correct. (As in fetch & Set we wait if value of S-> value is 1. So implementation is correct. This option is wrong.

Option (D) :- I don't see why this code does not implement binary semaphore, only one Process can be in critical section here at a time. So this is binary semaphore & Option D is wrong

Answer :- Option A. This is correct because the implementation may not work if context switching is disabled in P , then process which is currently blocked may never give control to the process which might eventually execute V. So Context switching is must !
View all questions of this test
Most Upvoted Answer
The atomic fetch-and-set x, y instruction unconditionally sets the mem...
Let us talk about the operation P(). It stores the value of s in x, then it fetches the old value of x, stores it in y and sets x as 1. The while loop of a process will continue forever if some other process doesn't execute V() and sets the value of s as 0. If context switching is disabled in P, the while loop will run forever as no other process will be able to execute V().
Free Test
Community Answer
The atomic fetch-and-set x, y instruction unconditionally sets the mem...


Explanation:

Context Switching:
- Context switching is the process of storing the state of a process or thread, so that it can be restored and resume execution later.
- In a system where context switching is disabled, the CPU does not switch between different processes or threads. This means that the CPU will not switch to another process while the current process is running.

Implementation of P Function:
- The P function uses atomic fetch-and-set operation to set the semaphore value to 1 and fetch the old value in y.
- The do-while loop ensures that the operation is repeated until the old value is fetched successfully.

Explanation of Option A:
- If context switching is disabled, the CPU will not switch to another process while the fetch-and-set operation is being executed in the P function.
- This can lead to a deadlock situation where other processes are unable to access the semaphore, causing the implementation to fail.

Therefore, option A is true as the implementation may not work if context switching is disabled in the P function.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. Can you explain this answer?
Question Description
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. 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 The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. 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 The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. Can you explain this answer?.
Solutions for The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. 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 The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. Can you explain this answer?, a detailed solution for The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. Can you explain this answer? has been provided alongside types of The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .void P (binary_semaphore *s) { unsigned y; unsigned *x = &(s->value); do { fetch-and-set x, y; } while (y);}void V (binary_semaphore *s) { S->value = 0;}Q.Which one of the following is true?a)The implementation may not work if context switching is disabled in P.b)Instead of using fetch-and-set, a pair of normal load/store can be usedc)The implementation of V is wrongd)The code does not implement a binary semaphoreCorrect answer is option 'A'. 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