This bounded buffer needs to be implemented programmatically. Use the fork() function to create the producer() and consumer() processes. Use a piece of shared memory for the buffer array. Use semaphores as detailed in the image below for the mutex, empty, and full semaphores.
Let the producer() function load the buffer with the alphabet, starting at 'a' and ending at 'z', and then repeating. Let it operate at a frequency of one letter per second.
Let the consumer() function read and display the buffer, one item at a time, at a frequency of 1 item every 3 seconds.
Bounded Buffer:
Thank you!
Variables:
type item buffer[n];
Semaphore mutex, empty, full;
Initialization:
mutex = 1; /* Provides mutual exclusion when accessing the buffer. */
empty = n; /* Counts the number of empty slots in the buffer. */
full = 0; /* Counts the number of full slots in the buffer. */
98
ProducerProcessO
ConsumerProcessO
repeat {
produceBufferItemO;
repeat {
wait(full);
wait(mutex);
wait(empty);
wait(mutex);
remove item from buffer;
add item to buffer;
signal(mutex);
signal(empty);
signal(mutex);
signal(full);
consumeBufferItemO;
} until(false);
} until(false);