I had a job process that was executing a lot of IO to read and write temporary files.
Now I want to (need to) reduce the quantity of IO executions.
So I want to create a sort of circular buffer that is going to be filled up with a data from a text file within first thread.
The consumer (reading) thread will fetch data from this buffer.
The problem is that there could be multiple consumers that need to read from same one buffer.
For buffer implementation I prefer not to use any existing wrappers (simple array, where i just "play" with indices is enough).
I also don't want to create a separate buffer for every reader. And ofcourse I want to avoid any deadlocks and unnecessary blockings.
Right now I am using circular buffer (an array and 2 indices)
The question is how to implement such buffer that can be accessed by multiple consumers where each consumer can read from it interdependently from other consumers (one costumer may read faster than the other one).
The first thread don't know (and should not know) about it's consumers!!! It should write data to a buffer, when data ends it should raise a flag.