The attached Producer-Consumer Algorithm below has one or more small modifications from the original. Note: Assume all

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

The attached Producer-Consumer Algorithm below has one or more small modifications from the original. Note: Assume all

Post by answerhappygod »

The attached
Producer-Consumer Algorithm below has one or more small
modifications from the original. Note: Assume all
initial values for variables/semaphores are the same as in the
original problem. Also assume that either process could begin
first.
Producer: do { 1p // produce an item 2p wait (empty); 3p wait (mutex); 4p // add the item to the buffer 5p signal (mutex); бр signal (empty); 7p } while (TRUE); Consumer: do [ 1c wait (full); 2c wait (mutex); 3c signal (mutex); 5c signal (full); // remove an item from buffer 40 2w бс // consume the item 7c } while (TRUE); 61 Writer: do { lw wait (wrt); // writing is performed 3w signal (wrt); 4w } while (TRUE); Reader: do {1r wait (mutex); 2r readcount++; 3r if (readcount == 1) 4r wait (wrt); 5r signal (mutex) 6r // reading is performed 7r wait (mutex); 8r readcount --;9r if (readcount == 0) 10r signal (wrt); 110 signal (mutex); 12r } while (TRUE);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply