Are there better ways to erase elements from tbb::concurrent_hash_map than using keys? #1435
xamidi
started this conversation in
Design discussions
Replies: 1 comment
-
|
FYI @kboyarinov |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am looking for a good way to erase elements from a huge
tbb::concurrent_hash_map<std::string, std::string>object.In an effort to replace
tbb::concurrent_unordered_mapbytbb::concurrent_hash_map(because the former does not support concurrent modification of elements), I came across the issue thattbb::concurrent_hash_mapcannot erase elements via iterator, but only via accessor or key.But my keys are strings (more precisely, formulas that are conclusions of a proof given as the value) and I would prefer to not collect a lot of them to merely remember which are to be erased, because this may result in millions of long strings to pollute the memory.
My code concurrently iterates over
tbb::concurrent_hash_map<string, string> representativeProofsin a specific way while not modifying it in order to find elements that should be removed, to then subsequently remove these elements.tbb::concurrent_unordered_map, I simply used iterators. I found no guarantees fortbb::concurrent_hash_mapthat iterators remain valid when other elements are removed, otherwise foriterator itI could useerase(it->first)(this still would require key-lookups, though).But somehow this results in undefined behavior. [Edit: Probably a lock around 'find()' would fix this?]
const_accessorso thattoErase[&it->first]can be avoided?erase(const_accessor)faster thanerase(key),const_accessors remain valid while other elements are removed, andconst_iterators really invalidated upon erasure of other elements?I could not find a documentation stating which guarantees can be made on the validity of iterators and accessors after which operations.
Or a safe code example of how to best remove elements while or after iterating.
So far the only reliable method seems to be erasure by stored keys (i.e. many
erase(const string&)here).But I suspect erasure via keys is also fine in parallel (in contrast, erasure is not thread-safe for
tbb::concurrent_unordered_map).Is copying and using (a potentially huge number of) the keys really the one and only best method?
Beta Was this translation helpful? Give feedback.
All reactions