- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
The concurrent operations (count, find, insert, and erase) invalidate any iterators pointing into the affected instance. It is unsafe to use these operations concurrently with any other operation.
so, I want to iterate and erase elements over concurrent_hash_map using accessor (not using iterator)
How can i do that?
[bash]Hash::accessor acc; for(Hash::iterator iter = map.begin(); iter != map.end() ; ++iter) { map.find(acc, iter->first); if( ~~) { map.erase(acc); } }[/bash]
is that a thread safe?
I wonder that erasing elements invalidate the iterator.
Thanks.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If erasing relatively few elements, store relevant keys into a vector, then revisit the map to erase the corresponding elements. If erasing most elements, copy selectively to new map and swap.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page