0
Answer

Array as a buffer in multithreading

Sandor

Sandor

17y
1.5k
1

Hello!

I have an array of MemoryStreams. The main thread is updating one element at a time and the other threads are iterating over the array and checking if they are free to read the elements. If a MemoryStream is locked in the array, they won't read it and continue to another MemoryStream in the array.

How can I implement this scenario? I'm using the array as a buffer, the threads are reading from it and sending data over network, that's why I can't allow the main thread do the work of reading and sending the data. I need to make the other threads recognize and not read the element that is being updated.

Thank you

Next Recommended Forum