Here is the situation: I have an application that is built around a central std::map instance. Inserts and updates are rare, but can happen. I now want to mirror this map to a database on disk on the fly (and keep it up to date). This work should be done by some thread in the background for performance reasons.
I am wondering what the best approach is. using std::shared_mutex I can have both the backup-thread and the main-thread read from the map simultaneously while ensuring the infrequent writes still work.
But how does the backup-thread iterate over the map? It cant use iterators as those are invalidated on insert.
[In addition, how to handle deletes best? Right now I have a protected vector<map_key> to_be_deleted
but this requires full locking between the backup-thread and the main-thread...]