WEEKS 8 & 9: Producer Consumer Problem

$24.99 $18.99

PROGRAM 1: Write a C Program to implement Producer-Consumer Problem using Semaphores This is similar to Week 7 Program but using Semaphores instead of Mutex locks. Implement a main program that creates two threads: producer and consumer threads which execute producer and consumer functions respectively. The producer should produce an item and update the buffer.…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

PROGRAM 1: Write a C Program to implement Producer-Consumer Problem using Semaphores

This is similar to Week 7 Program but using Semaphores instead of Mutex locks. Implement a main program that creates two threads: producer and consumer threads which execute producer and consumer functions respectively. The producer should produce an item and update the buffer. The consumer should consume an item and update the buffer. Use Semaphores (preferably unnamed semaphores) to enclose the critical sections in both producer and consumer so that only one of them can update the buffer at a time and prevent race condition as shown in the sample output below. Note: consumer should wait if buffer is empty and producer should signal when the buffer has at least one item. You can use bounded buffer.

Sample Output:

Your output can vary depending upon your implementation and the manner in which the threads are scheduled on your system but you should not see race condition.

PROGRAM 2: Write a C program to implement Producer Consumer problem using Pipes.

Create a simple pipe between producer and consumer using pipe() system call. The producer should write information to the write end of the pipe and the consumer should read information from the read end of the pipe and copy it to stdout.

Sample Output:

Your output can slightly vary depending upon your implementation

WEEKS 8 & 9: Producer Consumer Problem
$24.99 $18.99