Forums Register Login

Producer and consume optimistic code

+Pie Number of slices to send: Send
Hi...


I was just thinking that what would be the most optimistic design for the issue say if I have N number of producer threads and N number of consumer threads and consumer will act only when the producer has produces irrespective of which thread has produced and which thread is consuming, for this just a while loop or a for loop would not be enough to make the code most optimistic that is what I feel so if any one would like too share there comments about this please?
+Pie Number of slices to send: Send
The easy way is to have a single queue where the produces post their requests, and consumers read them. Would work OK if the requests take a long time to process compared to the time it takes to read then from the queue.
+Pie Number of slices to send: Send
I was just expecting any algorithm that can handle this issue in a much better way...
+Pie Number of slices to send: Send
You don't mean "optimistic" here do you?

Your exact case is not very interesting. Generalize it a bit, you have N threads/workers and M incoming requests. As long as N > M, then its not important what you do.

The interesting case is those times when N < M and especially when N is a lot less than M. This is exactly the reason that Java has the Thread pool concepts.
+Pie Number of slices to send: Send
 

Pat Farrell wrote:You don't mean "optimistic" here do you?



Agreed. "Optimistic" has a very specific meaning in terms of locking.

Also, "producer consumer" has a very specific meaning (aka pattern). And it generally involves an undetermined number of threads producing data, and an undetermined number of threads consuming the data. And the data communication is generally done via some sort of data structure, such as a queue.

Henry
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 881 times.
Similar Threads
Producer/Consumer Design impacts exception handling
regarding producer/consumer example
Should Threads performing independent tasks sleep?
Problem with Consumer/Producer implementation
Thread wait() and notify()
Producer Consumer Problem using Thread
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:05:07.