Ask Question
4 April, 00:15

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

+2
Answers (1)
  1. 4 April, 02:35
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers