If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I need to implement a two-way asynchronous communication between two objects, not using any IPC.

What I have now is a producer-consumer model where producer sends a number "88" to consumer at random intervals. Now, I need consumer to send a number "99" back to producer at a random intervals, this probably should be done in a separate thread. My prototype could be totally wrong for what I need hence I am open to any suggestions. I'd appreciate any help, thank you.

ANd how is any of this even remotely "asynchronous" ?
Asynchronous means that there will need to be some form of buffering on the producing side (the producer produces something when the consumer didn't ask for it). So any produced items will need to be "stored" somewhere until a consumer has had an opportunity to consume it.

And the consumer will either have polling to see if something has been produced (akin to a messageloop) or it will be waiting for a signal from the producer by waiting on a synchronisation object. Or some hybrid of both, polling for a certain time to fall asleep in a wait loop after a period of non activity from the producer.

Or rather you need two of these queues. They can be used to set up a two-way communication between your Producer and Consumer classes (which must run in separate threads (of which one may be the main thread)).

Sorry for coming back so late, I've been busy at work over timing. I know there should be a buffer for an asynchronous communication, I am just trying to figure out in which way the classes are aware of each other.

I am going to rethink what I need and I will close this thread for now.

I am going to rethink what I need and I will close this thread for now.

Yes it's obviously much better if you think before you ask.

But instead of asking detail questions about solutions you have in mind why not simply reveal up front what it is you want to accomplish. Top down problem solving and then bottom up coding is much more efficient.