Starting from:
$30

$24

WEEKS 8 & 9: Producer Consumer Problem

OBJECTIVE:

PROGRAM 1: Write a C program to implement Producer Consumer problem using Semaphores

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

 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






































 

More products