0

I've used very much the (Multi)Producer-Queue-Cosumer Design pattern, but I've no idea on how get the result of an operation.

I've 3 producer P1, P2, P3, that produce a message IMessage; this message is sent in a syncronized queue and elaborated from the Cosumer.

How can the consumer C tell to the producer (P1 or P2 or P3) that the request is finished and give the result?

Elvis Dukaj
  • 7,142
  • 12
  • 43
  • 85
  • Which language? Also, why do the producers need to know the result of the consumer? The producer should just produce as long as there is room in the queue. – Luis Feb 05 '13 at 15:18
  • I'm programmin in C++. I've to implement a system with lots of objects that need to poll other devices on a single rs232 serial port. One way is to lock the write/read operation. I'm cosidering the producer-consumer pattern because can be a easy way. – Elvis Dukaj Feb 05 '13 at 16:32
  • 1
    Queueing up request/reponse objects/structs/messages is usually easier to manage overall when compared with direct locking schemes, (and also easier to debug since only one thread interacts with the serial port). – Martin James Feb 05 '13 at 16:52

1 Answers1

1

One async way is for the consumer/s to queue the message back to its producer after completion. The message can contain result members, (and/or any exception object or error message that may have been raised during the message processing). Another possibility is that the producer simply waits on some sychro object that is also queued up with the message. The consumer signals it when done. Both these schemes ccould be supported by the producer loading up the message with an 'OnCompletion(Message *thisMessage)' function/event/delegate that the consumer calls when it has processed a message.

Martin James
  • 24,453
  • 3
  • 36
  • 60