title: local variables in threading function in Linux?
body: <pre><code>struct node
  {
  public:
      char *s;
      int up;
      node()
      {
          up = 0;
          s = new char[1000];
          memset (s, 0, sizeof(char) * 1000);
      }
      ~node()
      {
          delete [] s;
      }
      void insert()
      {
          s[up++] = 'a';
      }
  };
  
  void* test_thread(void *arg)
  {
      pthread_mutex_lock( &amp;mutex1 );
      node n;
      n.insert();
      printf ("%s\n", n.s);
      printf ("%x\n", &amp;n);
      pthread_mutex_unlock( &amp;mutex1 );
      pthread_exit(0);
      //return 0;
  }
  </code></pre>
  
  <p>supose this function will be executed by </p>
  
  <pre><code>pthread_create(&amp;id1, NULL, test_thread, NULL);
  pthread_create(&amp;id2, NULL, test_thread, NULL);
  </code></pre>
  
  <p>and it is compiled by</p>
  
  <pre><code>g++ test_thread.cpp -o main -lpthread -g 
  </code></pre>
  
  <p>its result is </p>
  
  <pre><code>a
  40a001a0
  a
  40a001a0
  </code></pre>
  
  <p>In my Linux operator ,the address of node n in the two thread are the same!</p>
  
  <p>I want to know why the address of node n in which the tho thread contains are the same? </p>
  
  <p>Any answer is appreciated~~~</p>
  
  <p>Thanks~~~</p>