title: How to handle shared resources with pthread mutex
body: <p>I have a question regarding mutex and pthreads.</p>
  
  <p>If there is a shared flag, lets call it (F1). And there are multiple threads.
  But only one thread (T1) can raise/cease the flag and all other threads (T2..Tn) only reads or pulls the status.</p>
  
  <p>Is it enough if T1 uses mutex_lock/mutex_unlock when the flag F1 will be set with a new value?
  Should all other threads also use mutex_lock/mutex_unlock even that they are only going to read the status from F1?</p>
  
  <pre><code>Exemple1:
  
      T1()
      {
          while(Running)
          {
              pthread_mutex_lock(&amp;lock);
              F1 = true;
              pthread_mutex_unlock(&amp;lock);
          }
      }
  
      T2()
      {
          while(Running)
          {
              if(F1) {
                  /* Do something */
              }
          }
      }
  
  
  
  Exemple2:
  
      T1()
      {
          while(Running)
          {
              pthread_mutex_lock(&amp;lock);
              F1 = true;
              pthread_mutex_unlock(&amp;lock);
          }
      }
  
      T2()
      {
          while(Running)
          {
              pthread_mutex_lock(&amp;lock);
              if(F1) {
                  /* Do something */
              }
              pthread_mutex_unlock(&amp;lock);
          }
      }
  </code></pre>