concurrent_hash_map() -- sorted insertion, sorting and thread-safe iteration

Raf Schietekat
Total Points:
16,805
Status Points:
16,805
Black Belt
July 4, 2009 3:15 PM PDT
Rate
 
#1
"In addition to not having a sort() method it seems that concurrent_hash_map() doesn't support sorted insertion?"
C++'s map is essentially an ordered tree, TBB's concurrent_hash_map is essentially a hash table. std::map doesn't support hashing, and access has logarithmic complexity, so it's not a one-sided deficiency: you just can't have it both ways at the same time, I guess.

"Can anyone from Intel confirm this, and give a valid reason why such a feature existing in standard hash_map) would be left out in TBB?"
If you don't mind my giving this a try: C++ is getting an "unordered_map" (say what? OMG!), and maybe a concurrent skip list could be considered in TBB's future (but you should check for yourself what has been written about this before, or maybe somebody could remind us).

"Furthermore, looking at the source code, accessors are thread-safe, but what about iterators?"
Do you have an example that makes sense with a hash map? And even so, complexity and performance considerations may require separate implementations without or with concurrent iterators, i.e., concurrent iterators don't come cheap.

"For example, how to advance through a sorted list of items in one thread which is controlled by user input (navigation keys) and add/remove items in sorted order from another thread while keeping everything thread-safe?"
In this situation a conventional locked std::map would do fine: users are so slow you might as well go to sleep waiting for them to do anything, you don't need the performance of a concurrent_hash_map(), let alone anything even faster, all with their own trade-offs between user features and performance.

"I am aware that I am not doing any parallel computation using concurrent_hash_map(), and therefore I am perhaps not using it as intended, but I would still like to have a thread-safe hash_map()."
It looks like you should write your own wrapper around std::map to hide the lock.

Intel Software Network Forums Statistics

8470 users have contributed to 31601 threads and 100650 posts to date.
In the past 24 hours, we have 29 new thread(s) 115 new posts(s), and 162 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member kopernikus