Hi,
I am required to have multiple threads writing to a single buffer (contiguous chunk of memory). The brute force method will be as follow
- The thread that wants to write to buffer will acquire lock on the buffer
- Entire buffer is locked and therefore only the thread that acquired lock can modify the buffer.
- The thread write to buffer.
- The thread unlocks the buffer.
This method serializes all threads because only one thread is active at given time. This turns out to be a bottleneck as the application spends majority of time writing to the buffer.
Could someone please suggest a method to increase parallelism while writing to single buffer?
Many thanks in advance.