Synchronized unordered_map in C ++

I am using unordered_map from Boost. Is there a synchronized version of unordered_map? This is due to the fact that I have a fairly large number of unordered_map and manual synchronization with the lock will be very dirty.

Thank.

+3
source share
4 answers

It is not possible to usefully encapsulate containers that offer STL-like interfaces (which also run unordered_map) with automatic locking, because there are race conditions associated with retrieving iterators and positions within the string, and then trying to use them in subsequent operations. If you can find some less flexible interface that suits your needs, perhaps if you include some complex operations in calls with one blocked function, then you can easily wrap the thread-protected class around the container to simplify your use .

+7
source

Are you sure this is what you need?

while (!stack.empty())
{
  Element const e = stack.top();


  stack.pop();
}

. , , .

, - , ?

. , TBB.

+4

Folly AtomicHashmap.

Github

folly/AtomicHashmap.h UnorderedAssociativeContainer, ( 2-5 , tbb:: concurrent_hash_map) . , , 32- .

.

+2

The Intel Thread Library contains a class tbb::concurrent_hash_mapthat is an unordered card that allows simultaneous access. Internally, it is implemented using a fine-grained blocking scheme, but the main result is that you can access it without race conditions.

+1
source

Source: https://habr.com/ru/post/1777631/


All Articles