Ask Question
5 September, 18:10

Design an algorithm for a bounded-buffer monitor in which the buffers (portions) are embedded within the monitor itself."

Assume the buffer can hold MAX_ITEMS items and each item is an integer. You should write two functions: void produce (int v) - This function is called by the producer to put item v in the buffer int consume () - This function is called by the consumer to remove an item in the buffer and returns the item

+3
Answers (1)
  1. 5 September, 18:29
    0
    Required code is given below:

    Explanation:

    monitor bounded buffer {

    int items[MAX ITEMS];

    int numItems = 0;

    condition full, empty;

    void produce (int v)

    {

    while (numItems = = MAX ITEMS) full. wait ();

    items[numItems++] = v;

    empty. signal ();

    }

    int consume ()

    {

    int retVal;

    while (numItems = = 0) empty. wait ();

    retVal = items[--numItems];

    full. signal ();

    return retVal;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Design an algorithm for a bounded-buffer monitor in which the buffers (portions) are embedded within the monitor itself." Assume the buffer ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers