I just hit a wall today with some of my work. I've been brainstorming but I'd like some outsider input
I have a multi-threaded application, right:
A producer, and 3 consumers, and a massive 1M structs buffer
Producer receives message, sets message in a buffer and increments (all atomically, don't worry about race conditions)
Each consumer reads message at current position, increments by x and goes to next message, in a way that no consumer hits the same data
If a consumer doesn't find any data, then it just sleeps and waits for the producer to broadcast on the next packet (I got this working, don't worry either)
But as you can see below, and what happens in real life, is that every packet, the consumers go to sleep, because the next packet isn't made for them yet... Which can be seen below:
Example:
Consumer1:036
Consumer2:147
Consumer3:258
Producer :012
(Notice that the first consumer goes to the next packet 2-steps before the producer gets to it's next packet
This is also the case when there's a steady inflow of packets per seconds (40000), since the consumers are SO fast, that they can handle packets at a microsecond level (It's probably gonna get slower, I didn't put encryption in yet) - but this is a problem if there's only let's say 1000 packets per second.
So my question to you, How would you make it so that producers don't sleep immediately after checking the next packet? assuming a steady flow ofc.
Thanks for reading this wall of text