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

Question No 2 (10) Consider a coke machine that has 14 slots. The producer is th

ID: 3833992 • Letter: Q

Question

Question No 2 (10) Consider a coke machine that has 14 slots. The producer is the delivery person and the consumer is the student using the machine. We use the following three semaphores: Semaphores: 1. Mutcx 2. Full Machine Number of filled slots 3. EluplyMacluiuc ulllber of CILuply slots Operations that are applicable on semaphores 1. wait semaphore 2. signal(semaphore s). Given uuructiolls Vscudo-code) delivery persol alld sludCILO 0 a) What will be the initial values of the semaphores? b) Write the missing solution that guarantees mutual exclusion and no deadlocks c) Identify the value: of CK) and (Y and (Z)? Part of the code tor student 0 function has been written) Initialize a/ #define NUM SLOTS 14 X semaphore Mutex Y) semaphore PullMachinc

Explanation / Answer

a.   The initial values of semaphores are:

Mutex = 1
FullMachine = 0
EmptyMachine = NUM_SLOTS


b.   The pseudo code can be written as follows:


delivery_person()
{
wait (EmptyMachine)
wait (Mutex)
put one Coke in machine
signal (Mutex)
signal (FullMachine)
}

student()
{
wait (FullMachine)
wait (machineFree)
put one Coke in machine
signal (machineFree)
signal (emptyBuffers)
}

   In the above code, notice that the Semaphores are not all being
used the same way. Mutex is simply acting as a mutex whose value
is always either 0 or 1

   FullMachine contains the number of cans of coke and Emptymachine counts the number of empty slots.

c.   At the beginning of the code, the semaphore values will be:
Mutex = 1
FullMachine = 0
EmptyMachine = 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote