Home > front end >  Making Consumer/Producer Problem a bit Advanced
Making Consumer/Producer Problem a bit Advanced

Time:05-07

Is there any way for the Consumer/Producer problem in synchronization could be made more advanced by introducing some scenario or making it a little bit more complex. The reason I am asking this is because at simpler level the Producer/Consumer problem is too easy and I have to make an end of semester project on it, so if any one have ideas regarding how can I make a decent intermediate/slightly advanced level version of this problem to implement.

Thanks.

CodePudding user response:

Spears it up in some cases? If consumer threads pass in the address of a local pointer where the dequeued item is to be placed, producer threads can directly load the result. That means that the consumer does not need to mess with any mutex once it is set running - it already has the dequeued item loaded. That implies that producer threads can identify which thread will be set running and so each consumer needs its own event/condvar/semaphore to wait on and that synchro stored in a container in the queue....or....

..you could store the synchro reference in the location pointed to by the consumer arg until it is required for signaling, at that time freeing up that local for storing the dequeued item. That means that only a pointer container is required in the PC queue struct.

Does this kind of chicanery help, or even work reliably?

Yes:)

  • Related