Got this problem straight from the book "Operating Systems" 2nd edition by Gary Nutt chapter 8 #13 and I'm having a hard time of it. Sorry for the wording it is the book. Need help.
I'm taking an Operating Systems class and stuck on a problem with Semaphores.
Here it is:
Suppose a machine's instruction set includes an instruction named swap that operates as follows (as an indivisible instruction):
swap(boolean *a, boolean *b)
t = *a;
*a = *b;
*b = t;
Show how swap can be used to implement the p and v operations.
You mean swap() is an "atomic" instruction - meaning it cannot be interrupted and will always execute to completion without a context-switch.
To reword the problem statement: If you have multiple threads calling p() and v(), how do you synchronize within the p() and v() implementation using only swap()? The fact that swap() takes a boolean is a big hint.
Thanks for the response and the hint. The book we are using is poorly written. They are going to get a new book next semester. In the meantime my class is the guinea pig.