@chkn I am having trouble designing the communication between producer and consumer.
I understand how the producer -> consumer way will go, but how do I make a request from the consumer (voice) to the producer (DFDServer) (these being “I need samples” and “I am no longer active”)?
Here is a rough description of the design I am thinking of:
- The producer (DFDServer) runs on a single background thread and it has a threadPool for serving multiple voices simultaneously. This technically means that the role of a “producer” is transferred to a threadPool job completing a read from the disk (it will write the samples to voice’s FIFO).
- The DFDServer has an “inbox” for each voice (for the backward communication) and in this line of communication it becomes the “consumer”. This “inbox” is also implemented with AbstractFifo and there, a voice adds requests to the DFDServer.
But I can’t figure these out:
- How do I implement the DFDServer’s continuous monitoring for new requests?
- It will be running on a background thread, but how do I make it start working (almost) immediately after a voice has posted a request for samples, without putting much load on the CPU (infinitely looping through the voices)?
- Is there a way to keep the DFDServer thread asleep and just wake it up when there is “mail”?
Any help is much appreciated.