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?
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.
Joined: Aug 10, 2006
I was just expecting any algorithm that can handle this issue in a much better way...
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.