title: Best practices for inter thread communication of large objects
body: <p>I need to be extremely concerned with speed/latency in my current multi-threaded project. </p>
  
  <p>Consider the following inter-thread communication:</p>
  
  <ul>
  <li>Thread #1: Processes a large object, call it <code>A</code>, that it receives from network events. This data significantly alters its internal state.</li>
  <li>Thread #2: Needs to know about the current, altered internal state of object <code>A</code> to make some set of decisions.</li>
  </ul>
  
  <p>I can think of essentially two methods to proceed:</p>
  
  <ol>
  <li><p>Thread #2 has a pointer to object <code>A</code>, and when signaled (say, through constantly checking a small object sent via a lockfree queue or by checking a shared atomic bool), Thread #2 locks object <code>A</code> and reads it.</p></li>
  <li><p>Thread #1 pushes some version of a copy of the object onto the lockfree queue so that thread #2 can simply receive it directly, use it, and dispose of the copy when it is finished.</p></li>
  </ol>
  
  <p>Method #1 avoids the costly copy of a large object needed for Method #2, but it always requires a lock/unlock and, if I understand things correctly, additional L3 cache hits.</p>
  
  <p>I understand there may not be any simple performance answers...that I may simply need to benchmark. I am mostly interested in best practices advice. Specifically, I'd like to know to think about the problem a cache memory level to know how information is being passed and copied internally.</p>