3 ms·
The problem with double-buffering is that you still need to know when all the readers are no longer using one of the copies. T1: writer populates copy1 T
by secondcoming 3y ago
The problem with double-buffering is that you still need to know when all the readers are no longer using one of the copies.
T1: writer populates copy1
T2: readers access copy1
T3: writer populates copy2, and swaps
T4: writer populates copy1, and swaps
At T4 a reader from T2 could still be accessing the old data structure.
Unless I'm overthinking it.
- AndrewStephens 3y agoNo, you are right. One solution is that the readers access the buffer through a shared_ptr and can hold onto the old version for as long as they need it while the writer makes changes and creates a wholly new data structure. It is also possible for the writer to block new readers while doing the swap. Tradeoffs everywhere, depending on if you need readers to see changes that occurred after they started accessing the data.
- to11mtm 3y agoNope, Ironically ran into this category of issue today with some buffer-reuse in a multi-threaded system.