944,155 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3204
  • Java RSS
Nov 12th, 2004
0

cheeky java program

Expand Post »
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);
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mellinda is offline Offline
17 posts
since Oct 2004
Nov 13th, 2004
0

Re: cheeky java program

That's C, not Java. And the code is far from complete, can you give more detail?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 14th, 2004
0

Re: cheeky java program

Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mellinda is offline Offline
17 posts
since Oct 2004
Nov 14th, 2004
0

Re: cheeky java program

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 14th, 2004
0

Re: cheeky java program

Quote 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mellinda is offline Offline
17 posts
since Oct 2004
Nov 14th, 2004
0

Re: cheeky java program

Most tutorials on multithreading in Java use this scenario (or a similar one) as an example.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Quality
Next Thread in Java Forum Timeline: can someone help i need to add a subclass





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC