It is kind of TSL instruction. Someone correct me if I am wrong.
The key point of this question is
"The atomic fetch-and-set x,y instruction sets the memory location x to 1 and the old value of x into y". It means following (understand the code snippet first)
CODE SNIPPET:
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;
}
UNDERSTAND HERE IN FOLLOWING STEPS:
1. Suppose s.value==0 initially. and &(s->value)==100.
2. unsigned *x=&(s->value) will assign 100 to x.
3. fetch-and-set x,y; <- this statement will set value of location stored in x to 1 i.e, s.value=1. (REMEMBER BINARY SEMAPHORE'S STRUCTURE CONSISTS VALUE AND QUEUE FIELD ) and older value of location stored in x will be stored in y i.e, y=0.
I think this is one of the main difficulties of the question for many. Now you can solve the question.