title: C++ concurrent associative containers?
body: <p>I'm looking for a associative container of some sort that provides safe concurrent read &amp; write access provided you're never simultaneously reading and writing the <em>same</em> element.</p>
  
  <p>Basically I have this setup:</p>
  
  <p><strong>Thread 1:</strong> Create A, Write A to container, Send A over the network.</p>
  
  <p><strong>Thread 2:</strong> Receive response to A, Read A from container, do some processing.</p>
  
  <p>I can guarantee that we only ever write A once, though we may receive multiple responses for A which will be processed serially.  This also guarantees that we never read and write A at the same time, since we can only receive a response to A after sending it.</p>
  
  <p>So basically I'm looking for a container where writing to an element <em>doesn't</em> mess with any other elements.  For example, <code>std::map</code> (or any other tree-based implementation) does not satisfy this condition because its underlying implementation is a red-black tree, so any given write may rebalance the tree and blow up any concurrent read operations. </p>
  
  <p>I think that <code>std::hash_map</code> or <code>boost::unordered_set</code> may work for this, just based on my assumption that a normal hash table implementation would satisfy my criteria, but I'm not positive and I can't find any documentation that would tell me.  Has anybody else tried using these similarly?</p>