Posts

Showing posts from March, 2017

PRODUCER CONSUMER PROBLEM

PRODUCER CONSUMER PROBLEM The producer-consumer problem(also know as bounded buffer problem) in real life is a classic problem faced while solving the multi-process synchronization problem.  As considered in real-life the producer-consumer use a fixed buffer (storage space) for producing or consuming goods(i.e the resources). The problem may arise if the producer and the consumer are not in synchronization. If the producer produced more than required or the consumer is trying to consume more than the produced material. To solve this problem using semaphores the program is given below: import java.util.concurrent.Semaphore;  class globe{      //for counting the number of items the varialble is made global. public class ConsumerProducer{     public static void main(String[] args)     do   ch=sc.nextInt();        break;                                           else Output: semaphoreProducer permit=1 | semaphoreConsumer permit=0 1 import java.lang.*; import java.util.*;   pu