title: How does POSIX Threads work in linux?
body: <p>I thought pthread uses <em>clone</em> to spawn one new <em>thread</em> in linux. But if so, all of the threads should have their seperate <em>pid</em>. Otherwise, if they have the same <em>pid</em>, the global variables in the <em>libc</em> seem to be shared. However, as I ran the following program, I got the same <em>pid</em> but the different address of <em>errno</em>. </p>
  
  <pre><code>extern errno;
  void*
  f(void *arg)
  {
      printf("%u,%p\n", getpid(), &amp;errno);
      fflush(stdin);
      return NULL;
  }
  
  int
  main(int argc, char **argv)
  {
      pthread_t tid;
      pthread_create(&amp;tid, NULL, f, NULL);
      printf("%u,%p\n", getpid(), &amp;errno);
      fflush(stdin);
      pthread_join(tid, NULL);
      return 0;
  }
  </code></pre>
  
  <p>Then, why?</p>