title: Is it safe to read a locked variable in shared memory?
body: <p>For example, I have a variable</p>
  
  <pre><code>struct sth {
      int abcd;
      pthread_mutex_t mutex;
  };
  </code></pre>
  
  <p>I have two method</p>
  
  <pre><code>setSth(int a) {
    lock();
    sth-&gt;abcd = a;
    unlock();
  }
  
  getSth() {
    return sth-&gt;abcd;
  }
  </code></pre>
  
  <p><code>sth</code> will never be freed. Is it safe not use <code>lock/unlock</code> in getSth()? I don't care accuracy.</p>
  
  <p>By safe I mean there's no segfault thing.</p>