2,592 views
3 votes
3 votes
Consider the producer-consumer problem solution using semaphore.
Which of the following condition below synchronization mechanism satisfies.
  1.  Mutual Exclusion 
  2. Bounded Waiting
  3. Progress
  4. Architecural Neutral
mutex buffer_mutex; // similar to "semaphore buffer_mutex = 1", but different (see notes below)
semaphore fillCount = 0;
semaphore emptyCount = BUFFER_SIZE;

procedure producer() {
    while (true) {
        item = produceItem();
        down(emptyCount);
            down(buffer_mutex);
                putItemIntoBuffer(item);
            up(buffer_mutex);
        up(fillCount);
    }
}

procedure consumer() {
    while (true) {
        down(fillCount);
            down(buffer_mutex);
                item = removeItemFromBuffer();
            up(buffer_mutex);
        up(emptyCount);
        consumeItem(item);
    }
}

1 Answer

Related questions

0 votes
0 votes
1 answer
4
ajayraho asked Oct 23, 2022
876 views
What is the significance of infinite loop that is written in every example of process synchronisation? What would happen if there wasn't any infinite loop?