Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

Advertisements


website counter



producer consumer program


Posted Date: 28 Mar 2008    Resource Type: Articles/Knowledge Sharing    Category: Education

Posted By: sasi kala       Member Level: Gold
Rating:     Points: 4



Producer and Consumer

#include
#include
int mutex=1,full=0,empty=3,x=0;
void main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
clrscr();
printf("list of choices :\n1.producer \n2.consumer \n3.exit");
while(1)
{
printf("\n\n enter the choice:");
scanf("%d",&n);
switch(n)
{
case 1:
if((mutex==1)&&empty!=0)
producer();
else
printf("\n buffer is full");
break;
case 2:
if((mutex==1)&&full!=0)
consumer();
else
printf("\n buffer is empty");
break;
case 3:
exit(0);
break;
}
}











}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return(++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\n producer produces the item %d:",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes an item %d:",x);
x--;
mutex=signal(mutex);
}






















OUTPUT:



enter the choice:1
producer produces the item 3:

enter the choice:1
buffer is full

enter the choice:2
consumer consumes an item 3:

enter the choice:2
consumer consumes an item 2:

enter the choice:2
consumer consumes an item 1:

enter the choice:2
buffer is empty

enter the choice:3





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: syllabus...BITS
Previous Resource: win32application program
Return to Discussion Resource Index
Post New Resource
Category: Education


Post resources and earn money!
 
Related Resources


Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.