title: Thread-safety with C++ and passing by reference
body: <p>I wanted to confirm my understanding of threads and passing by reference in C++. Is the following function thread safe?</p>
  
  <pre><code>QString sA = "hello";
  QString sB = "world";
  bool someFlag = AreStringsEqual(sA,sB);
  
  ...
  
  bool AreStringsEqual(QString const &amp;stringA, QString const &amp;stringB)
  {
      if(stringA == stringB)
      {   return true;   }
  
      return false;
  }
  </code></pre>
  
  <p>I think it <em>is</em> thread safe. I'd like it if someone could confirm my thought process, or tell me I have no idea what I'm talking about :) </p>
  
  <ul>
  <li><p>There are two copies of sA and sB in the process's memory. One set is created on Thread1's stack and the second set is created on Thread2's stack. Because we passed by reference, each thread only needs one set of sA and sB in memory to execute the function call.</p></li>
  <li><p>If we had passed by value instead, there could be up to four copies of sA and sB in the process's memory (each thread having two sets) at some time point where both threads were trading processor control within the function call.</p></li>
  <li><p>In no case is memory shared here, therefore the function is thread safe.</p></li>
  </ul>
  
  <p>Sorry if this question is super simple, threads have fried my brain :)</p>
  
  <p>Pris</p>