User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 430,121 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,328 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2070 | Replies: 5
Reply
Join Date: Oct 2004
Posts: 17
Reputation: mellinda is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mellinda mellinda is offline Offline
Newbie Poster

Help cheeky java program

  #1  
Nov 12th, 2004
hia, the below program is a Simulation of Producer-Consumer Problem using Race Condition.Please can anyone help me to finish this program in java language.Thanks a lot
lux melxxx

Producer/Consumer code

int BUFFER_SIZE = 100;
int count = 0;
 
void producer(void) {
int item;
while(TRUE) {
produce_item(&item);
if(count == BUFFER_SIZE) sleep ();
enter_item(item);
count++;
if(count == 1) wakeup(consumer);
}
}
 
void consumer(void) {
int item;
while(TRUE) {
if(count == 0) sleep ();
remove_item(&item);
count--;
if(count == BUFFER_SIZE - 1) wakeup(producer);
consume_item(&item);
}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,355
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 29
Solved Threads: 466
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: cheeky java program

  #2  
Nov 13th, 2004
That's C, not Java. And the code is far from complete, can you give more detail?
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Oct 2004
Posts: 17
Reputation: mellinda is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mellinda mellinda is offline Offline
Newbie Poster

Re: cheeky java program

  #3  
Nov 14th, 2004
Originally Posted by Narue
That's C, not Java. And the code is far from complete, can you give more detail?


hia, i want to write the program in java language.The program is a Simulation of Producer-Consumer Problem using Race Condition, using SLEEP/WAKEUP.
chessxx
Reply With Quote  
Join Date: Sep 2004
Posts: 6,355
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 29
Solved Threads: 466
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: cheeky java program

  #4  
Nov 14th, 2004
>i want to write the program in java language
Then you're using the wrong language.

>The program is a Simulation of Producer-Consumer Problem using Race Condition, using SLEEP/WAKEUP.
Typically when I ask for more detail, I'm looking for something other than a regurgitated version of the original question with an addition that's obvious from looking at the code. You haven't told me anything new, but I'll give you one more try before I plonk you.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Oct 2004
Posts: 17
Reputation: mellinda is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mellinda mellinda is offline Offline
Newbie Poster

Re: cheeky java program

  #5  
Nov 14th, 2004
Originally Posted by Narue
>i want to write the program in java language
Then you're using the wrong language.

>The program is a Simulation of Producer-Consumer Problem using Race Condition, using SLEEP/WAKEUP.
Typically when I ask for more detail, I'm looking for something other than a regurgitated version of the original question with an addition that's obvious from looking at the code. You haven't told me anything new, but I'll give you one more try before I plonk you.

Right, i want to have one producer, one consumer and a buffer of size 100.Everytime the consumer consume, buffer size is decrease by one and producer is notified and vice-versa.
Any help of coding will be really appreciazted but if not thank you.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: cheeky java program

  #6  
Nov 14th, 2004
Most tutorials on multithreading in Java use this scenario (or a similar one) as an example.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 3:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC