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?
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.
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 .
The ConcurrentHashMap operations are thread-safe. ConcurrentHashMap doesn't allow null for keys and values.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With