
Write a C program
Producer – Consumer as a classical problem of synchronization
Step 2. Write a program* that solves the producer - consumer problem. You may use the following pseudo code
for implementation.
*program to write: produce -consumer problem to produce and consume the alphabet.
//Shared data: semaphore full, empty, mutex;
//pool of n buffers, each can hold one item
//mutex provides mutual exclusion to the buffer pool
//empty and full count the number of empty and full buffers
//Initially: full = 0, empty = n, mutex = 1
//Producer thread
do {
…
produce next item
…
wait(empty);
wait(mutex);
…
add the item to buffer
…
signal(mutex);
signal(full);
} while (1);
//Consumer thread
do {
wait(full)
wait(mutex);
…
remove next item from buffer
…
signal(mutex);
signal(empty);
…
consume the item
} while (1);

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- Please write code n C. and use the alphabet Producer – Consumer as a classical problem of synchronization Step 2. Write a program* that solves the producer - consumer problem. You may use the following pseudo code for implementation. *program to write: produce -consumer problem to produce and consume the alphabet. //Shared data: semaphore full, empty, mutex; //pool of n buffers, each can hold one item //mutex provides mutual exclusion to the buffer pool //empty and full count the number of empty and full buffers //Initially: full = 0, empty = n, mutex = 1 //Producer thread do { ... produce next item ... wait(empty); wait(mutex); ... add the item to buffer ... signal(mutex); signal(full); } while (1); //Consumer thread do { wait(full) wait(mutex); ... remove next item from buffer ... signal(mutex); signal(empty); ... consume the item ... } while (1);arrow_forwardWrite a C program to Implement the Indexed allocation strategy.arrow_forwardConsider a system where free space is kept in a free-space list. a. Suppose that the pointer to the free-space list is lost. Can the system reconstruct the free-space list? Explain your answer. b. Consider a file system similar to the one used by UNIX with indexed allocation. How many disk 1/0 operations might be required to read the contents of a small local file at /a/b/c? Assume that none of the disk blocks is currently being cached. c. Suggest a scheme to ensure that the pointer is never lost as a result of memory failure.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





