Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write three very simple, non-looping programs that use shared binary semaphor

ID: 3576427 • Letter: 1

Question

1) Write three very simple, non-looping programs that use shared binary semaphores, such that deadlock among all three could occur if nothing was done to prevent it. Give a scenario in which the three programs would deadlock.

2) A memory manager for a variable-sized region strategy has a free list of blocks of size 600, 400, 1000, 2200, 1600, and 1050 bytes.

a) What block will be selected to honor a request for 1603 bytes using the best-fit policy?

b) What block will be selected to honor a request for 949 bytes using the best-fit policy?

c) What block will be selected to honor a request for 349 bytes using the worst-fit policy?

d) Assume the free list is ordered as the blocks are listed in the problem statement. What block will be selected to honor a request for 1603 bytes using the first-fit policy?

e) Assume the free list is ordered as the blocks are listed in the problem statement. What block will be selected to honor a request for 11049 bytes using the first-fit policy?

Explanation / Answer

1. Three simple programs !

Assumption : 3 binary semaphores S1,S2,S3

Program 1

void P1 {

down(S1);

down(S2);

down(S3);

CS(); // Critical Section

up(S3);

up(S2);

up(S1);

}

==============

Program 2

void P2 {

down(S2);

down(S3);

down(S1);

CS(); // Critical Section

up(S1);

up(S3);

up(S2);

}

===============

Program 3

void P3 {

down(S3);

down(S1);

down(S2);

CS(); // Critical Section

up(S2);

up(S1);

up(S3);

}

Deadlock is a state when each member of group is waiting for some other member(s) to release a lock !

Explanation : A deadlock scenario is when P1 executes down(S1), followed by a context
switch which allows P2 to execute down(S2), followed by a context switch
that allows P3 to execute down(S3).