title: when using mutex, "printf" output twice(or more?I'm not sure)?
body: <p>I was learning threading synchronization. My test code is as follow:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  
  pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  int count = 0;
  void* add(void * params)
  {
      while(1)
      {
          pthread_mutex_lock(&amp;mutex);
          fprintf(stdout, "thread:%ld, count:%d\n",pthread_self(), count);
          count++;
          pthread_mutex_unlock(&amp;mutex);
      }
      return 0;
  }
  
  void* print(void * params)
  {
      while(1)
      {
          pthread_mutex_lock(&amp;mutex);
          if (count &gt; 100)
          {
              printf("count greater than 100,count: %d\n", count);
              pthread_mutex_unlock(&amp;mutex);
              break;
          }
          pthread_mutex_unlock(&amp;mutex);
      }
      return 0;
  }
  
  int main(void)
  {
      pthread_t thread1, thread2, thread3;
      pthread_mutex_init(&amp;mutex, NULL);
      pthread_create(&amp;thread1, NULL, add, NULL);
      pthread_create(&amp;thread2, NULL, add, NULL);
      pthread_create(&amp;thread3, NULL, print, NULL);
      pthread_join(thread3, NULL);
      pthread_mutex_destroy(&amp;mutex);
  
      return 0;
  }
  </code></pre>
  
  <p>I thought every output of "count" will increased by one successively. However, the truth was quite different.Just like:</p>
  
  <blockquote>
    <p>//program output begin: thread:139663694870272, count:0
    thread:139663694870272, count:1 thread:139663694870272, count:2
    thread:139663694870272, count:3 thread:139663694870272, count:4
    thread:139663694870272, count:5 thread:139663686477568, count:6
    thread:139663686477568, count:7 thread:139663686477568, count:8
    thread:139663686477568, count:9 thread:139663686477568, count:10
    thread:139663686477568, count:11 thread:139663686477568, count:12
    thread:139663686477568, count:13 thread:139663686477568, count:14
    thread:139663686477568, count:15 thread:139663686477568, count:16
    thread:139663686477568, count:17 thread:139663686477568, count:18
    thread:139663686477568, count:19 thread:139663686477568, count:20
    thread:139663686477568, count:21 thread:139663686477568, count:22
    (...............some lines were ignored)thread:139663686477568,
    count:172 count greater than 100,count: 173 thread:139663686477568,
    count:173 thread:139663686477568, count:174 thread:139663686477568,
    count:175 thread:139663686477568, count:176 thread:139663686477568,
    count:177 thread:139663686477568, count:178 thread:139663686477568,
    count:179 thread:139663686477568, count:180 thread:139663686477568,
    count:181 thread:139663686477568, count:182 thread:139663686477568,
    count:183 thread:139663686477568, count:184 thread:139663686477568,
    count:185 thread:139663686477568, count:186 thread:139663686477568,
    count:187 thread:139663686477568, count:188 thread:139663686477568,
    count:189 thread:139663686477568, count:190 thread:139663686477568,
    count:191 thread:139663686477568, count:192 thread:139663686477568,
    count:193 thread:139663686477568, count:194 thread:139663686477568,
    count:195 thread:139663686477568, count:196 thread:139663686477568,
    count:197 thread:139663686477568, count:198 thread:139663686477568,
    count:199 thread:139663686477568, count:200 thread:139663686477568,
    count:201 thread:139663686477568, count:202 thread:139663686477568,
    count:203 thread:139663686477568, count:204 thread:139663686477568,
    count:205
    <strong>thread:139663686477568, count:206 thread:139663686477568, count:206</strong> thread:139663686477568, count:207 thread:139663686477568,
    count:208 thread:139663686477568, count:209
    <strong>thread:139663686477568, count:210 thread:139663686477568, count:210</strong> thread:139663686477568, count:211</p>
  </blockquote>
  
  <p>I don't konw what "printf" do in this case? Why it output twice.</p>