- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The comments in the file concurrent_hash_map.h indicate that using iterators, begin(), and end() are not thread safe. What is the recommended way to iterate the items in a concurrent_hash_map in a thread safe way? If the answer is "put a mutex around the code that does the iteration" then I also have to put a mutex around find/insert/remove, which sort of defeats the concurrency. I need a way to access all of the elements in the hash map read only - I don't need to modify the elements or remove them during the iteration.
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could read the manual, or search this forum. "How to lock the whole concurrent_hash_map not warping a portion of code with mutex?" is a very recent thread dealing about a suspiciously similar issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. I was using tbb 2.2 2.20090809 in Red Hat Enterprise Linux EPEL (Fedora) 6 which does not have concurrent_unordered_map. I see that there is tbb 3.0 in more recent versions of Fedora which has concurrent_unordered_map.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe you could disable the package that comes with your distribution and install a more recent one directly from Intel?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you give me an code example to show how to do safe iteration of concurrent_hash_map? Document "How to lock the whole concurrent_hash_map not warping a portion of code with mutex?" just can't be opened now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would seem that that other thread contained the suggestion to use concurrent_unordered_map instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you can afford not using erase(), concurrent_unordered_map is the best choice. Otherwise, there is a hackish way to traverse concurrent_hash_map if certain constraints are preserved: https://software.intel.com/en-us/blogs/2010/05/14/traversing-concurrent_hash_map-concurrently
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