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

type in the microsoft word and then take a picture uploaded it structions Bounde

ID: 3877794 • Letter: T

Question

type in the microsoft word and then take a picture uploaded it

structions Bounded Buffer problem is another example of a classic synchronization problem. There are many variants of this problem, one f which is examined below. Bounded Buffer Problem ded buffer problem, which is also called producer consumer problem, is one of the classic problems of synchronization ·This problem, is generalized in terms of the Producer-Consumer problem. Problem Statement: There is a buffer of n slots and each slot is capable of storing one unit of data. There are two processes running, namely, producer and consumer, which are operating on the buffer. Buffer of n slots might have guesse i an empty slot of the buffer A consumer tries to remove data from filled slot in the buffer. As YOu might have guessed by now, those two processes won't produce the expected output if they are being executed concurrently. There needs to be a way to make the producer and consumer work in an independent manner.

Explanation / Answer

This problem can be solved by using Semaphores. Semaphores, depending on the value the process can use the resource or will find that it is already in use and then must wait for some period before trying again.

         The following are the semaphores used in This Bounded Buffer Problem:

Empty represents the number of empty slots in buffer and full represents the number of occupied slots in the buffer.

Producer Operation:

do {

    wait (empty);    // wait until empty>0 and then decrement ‘empty’

    wait(mutex);    // lock

    /* perform the insert operation in a slot */

    signal(mutex); // release lock

    signal(full);   // increment ‘full’

} while(TRUE)

Here as shown in above producer will waits until there is empty slot.

If empty slot found then it decrements the empty semaphore because, there will be one more empty slot is adding.

Then it lock on the buffer, so consumer cannot access the buffer until the producer releases it.

After performing some operation the lock is released and the value of full is incremented as produced just filled a slot in the buffer.

Consumer Operation:

do {

wait(full); // wait until full>0 and then decrement ‘full’

wait(mutex); // acquire the lock

/* perform the remove operation

   in a slot */

signal(mutex); // release the lock

signal(empty); // increment ‘empty’

} while(TRUE);

The consumer waits until atleast one full slot in the buffer.

Then it decrements the full semaphore because the Occupied slots will be decreased by one.

After that consumer lock on the buffer.

Then consumer complete the removal or some operation so that data from one full slot is removed.

Then consumer releases the lock.

Finally the empty semaphore is incremented by , as consumer just removed data from slot, thus making it empty.