Producer Consumer Problem Solution

an anonymous user · November 25, 2022
#include <stdio.h>
int size = 0;
int buffer = 0;
int choice = 0;
int mutex = 1;

void ask_size();
void ask();
int available();
int overflow();
int underflow();
void produce();
void consume();

void main() {
    ask_size();
    do {
        ask();
        switch(choice) {
            case 1:
            if (available() && !overflow()) produce();
            else printf("\nItem not Produced\n");
            break;
            case 2:
            if (available() && !underflow()) produce();
            else printf("\nItem not Consumed\n");
            break;
            case 3:
            printf("\nBuffer: %d\n", buffer);
            break;
            case 4:
            break;
        }
    } while (choice != 4);
}
Output
(Run the program to view its output)

Comments

Please sign up or log in to contribute to the discussion.