CS604 Assignment No 5 Spring 2012 solution

Question 1:
Let as consider a female Shabnam working in a beauty parlor. Shabnam use to do make only. In beauty parlor there are two rooms. One room is called make up room and the second room is called rest room. Rest room is used for waiting and the Make up room is used for make up. In make up room Shabnam do make of a female client (only one at a time) and in the rest room female clients keep waiting for their turns. Beauty parlor has n number of sofas in rest room. And the make up room contains the sofa for Shabnam. When there will be no female client to be served then Shabnam will start sleeping on her sofa. But if a female client enters beauty parlor and she finds that no sofa is empty i.e. they are all occupied then female client will leave the beauty parlor. However, if a female client enters beauty parlor and she finds that Shabnam is doing a make up of any other female client then she will sit on one of the available sofa in beauty parlor. However, if a female client enters beauty parlor and she finds that Shabnam is sleeping then female client will wake up Shabnam.

You need to write a C program or Pseudo code that uses semaphores, wait and signal operations to SYNCHRONIZE Shabnam and female client.

Solution

Semaphore custReady = 0         # if 1, at least one customer is ready
Semaphore barberReady = 0
Semaphore accessWRSeats = 1       # if 1, the # of seats in the waiting room can be incremented or decremented
int numberOfFreeWRSeats = N     # total number of seats in the waiting room

def Barber():
while true:                   # Run in an infinite loop.
wait(custReady)             # Try to acquire a customer – if none is available, go to sleep.
wait(accessWRSeats)         # Awake – try to get access to modify # of available seats, otherwise sleep.
numberOfFreeWRSeats+=  1    # One waiting room chair becomes free.
signal(barberReady)         # I am ready to cut.
signal(accessWRSeats)       # Don’t need the lock on the chairs anymore.
# (Cut hair here.)

def Customer():
while true:                   # Run in an infinite loop.
wait(accessWRSeats)         # Try to get access to the waiting room chairs.
if numberOfFreeWRSeats > 0: # If there are any free seats:
numberOfFreeWRSeats-= 1   #   sit down in a chair
signal(custReady)         #   notify the barber, who’s waiting until there is a customer
signal(accessWRSeats)     #   don’t need to lock the chairs anymore
wait(barberReady)         #   wait until the barber is ready
# (Have hair cut here.)
else:                       # otherwise, there are no free seats; tough luck —
signal(accessWRSeats)     #   but don’t forget to release the lock on the seats!
# (Leave without a haircut.)

Question 2:
Q. Let us consider a page size of 16 bytes and process address space of 32 pages and physical address space of 64  frames. Calculate the following.
a) Number of bits needed for ‘p’.
b) Number of bits needed for ‘f’.
c) Number of bits needed for ‘d’.
d) Size of logical address i.e. Number of bits needed to uniquely identify a page in this address space of 16
pages.
e) Logical address in bits for (18, 10). Where ‘p’ and ‘d’ are 18 and 10 respectively.

Solution:

a) Number of bits needed for ‘p’. = 5 bits

b) Number of bits needed for ‘f’.  = 6 bits

c) Number of bits needed for‘d’.   = 8 bit

d) Size of logical address i.e. Number of bits needed to uniquely identify a page in this address space of 16 pages.  = 12 bit

e) Logical address in bits for (18, 10). Where ‘p’ and‘d’ are 18 and 10 respectively. = 28 bit

DOWNLOAD SOLUTION HERE
loading...