question about concurrent map

question about concurrent map

What is the difference between the unordered concurrent map and the concurrent hash map? What I mean is, why would I want to chose one over the other? The documention doesnt necessarily explain the pros and cons of the two, but only explains a few differences in functionality without explaining why the differences exist. Are there speed differences in insert? the unordered container cannot saftely erase objects --great. So why would anyone use unordered concurrent map?

Also, a follow up question, is there a way to iterate over the concurrent hash map without holding locks for each element as I go? For example, I know that a certain part of my code is going to be serial and I want to iterate over the container and do some work, is there a way to skip the automatic locking?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The main difference is that concurrent_unordered_map provides a simpler API, more consistent with that of maps in the C++ standard library, at the cost of erase() being not a concurrent operation.

As for performance/speed differences, those might depend on a setup, and may change with future improvements.

For the follow-up question: the traversal of concurrent_hash_map is not safe if there are concurrent operations running, but you can safely use it in serial code sections. An iterator can be obtained with begin(), end(), and equal_range(key) methods.

Leave a Comment

Please sign in to add a comment. Not a member? Join today