Binary semaphore delay

1.Another atomic machine instruction that supports mutual exclusion that is often

mentioned in the literature is the test&set instruction, defined as follows:

boolean test_and_set (int i)

if (i == 0)

i = 1;

return true;

else return false;

Define a procedure similar to those of Figure 5.2 that uses the test&set instruction.

2. It should be possible to implement general semaphores using binary semaphores.We

can use the operations semWaitB and semSignalB and two binary semaphores,

delay and mutex. Consider the following:

void semWait(semaphore s)

semWaitB(mutex);

s—;

if (s < 0)=””>

semSignalB(mutex);

semWaitB(delay);

else SemsignalB(mutex);

void semSignal(semaphore s);

semWaitB(mutex);

s++;

if (s <=>

semSignalB(delay);

semSignalB(mutex);

Initially, is set to the desired semaphore value. Each semWait operation decrements

s, and each semSignal operation increments s.The binary semaphore mutex,

which is initialized to 1, assures that there is mutual exclusion for the updating of s.

The binary semaphore delay, which is initialized to 0, is used to block processes.

There is a flaw in the preceding program. Demonstrate the flaw and propose a

change that will fix it. Hint: Suppose two processes each call semWait(s) when s is

initially 0, and after the first has just performed semSignalB(mutex) but not performed

semWaitB(delay), the second call to semWait(s) proceeds to the same

point. All that you need to do is move a single line of the program.

WhatsApp
Hello! Need help with your assignments?

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

🛡️ Worried About Plagiarism? Run a Free Turnitin Check Today!
Get peace of mind with a 100% AI-Free Report and expert editing assistance.

X