Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ 11 equivalent of java.util.ConcurrentHashMap

I find myself constantly writing Mutex code in order to synchronize read/write access to a std::unordered_map and other containers so that I can use them as I do java.util.concurrent containers. I was about to start writing a wrapper to encapsulate the Mutex, but I would rather use a well tested library so I don't stuff up the threading.

Is there such a library?

like image 834
Jon N Avatar asked Apr 20 '13 09:04

Jon N


People also ask

What is Java Util concurrent ConcurrentHashMap?

A hash table supporting full concurrency of retrievals and high expected concurrency for updates. This class obeys the same functional specification as Hashtable and includes versions of methods corresponding to each method of Hashtable.

Which is better HashTable or ConcurrentHashMap?

ConcurrentHashMap uses multiple buckets to store data. This avoids read locks and greatly improves performance over a HashTable . Both are thread safe, but there are obvious performance wins with ConcurrentHashMap .

Is ConcurrentHashMap remove thread-safe?

The ConcurrentHashMap operations are thread-safe. ConcurrentHashMap doesn't allow null for keys and values.


1 Answers

Intel produced a library called Threading Building Blocks which has two such things: concurrent_hash_map and concurrent_unordered_map. They have slightly different characteristics, but one or the other will probably suit your needs.

like image 67
John Zwinck Avatar answered Sep 19 '22 09:09

John Zwinck