title: How is thread stack created in C?
body: <p>Let's say we have the following program:</p>
  <pre><code>int main() {
     pthread_t tid;
     Pthread_create(&amp;tid, NULL, thread, NULL);
     Pthread_join(tid, NULL);
     ... //do some other work                    
     exit(0);
  }
  
  void *thread(void *vargp) {
     ...//do sth
     return NULL;
  }
  </code></pre>
  <p>Below is a picture that shows the main thread stack:
  <a href="https://i.stack.imgur.com/JnjiC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JnjiC.png" alt="enter image description here" /></a></p>
  <p>My question is, after a new thread is created, how does the new thread's own stack look like? does the beginning of the new stack start right after the main thread as:
  <a href="https://i.stack.imgur.com/TyAvU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TyAvU.png" alt="enter image description here" /></a></p>
  <p>or the new thread's stack's beginning address can be any random address, therefore leaving  &quot;splinters&quot; as:</p>
  <p><a href="https://i.stack.imgur.com/vqujM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vqujM.png" alt="enter image description here" /></a></p>
  <p>I know due to virtual address, the virual pages can be anywhere in the physical disk, but I just want to know if the virtual address itself is continuous or not.</p>