问题
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?
回答1:
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.
回答2:
Folly has an AtomicHashmap implementation. The major limitation is that you can only use int32 or int64 keys. Check the documentation here (specially the Limitation section)
来源:https://stackoverflow.com/questions/16118889/c-11-equivalent-of-java-util-concurrenthashmap