title: Simple example for pthread_join deadlock
body: <p>I am looking for a very simple example to demonstrate a deadlock using <code>pthread_join</code>; however, this is not trivial.</p>
  
  <p>I started with this:</p>
  
  <pre><code>void* joinit(void* tid)
  {
    pthread_t* tid_c = (pthread_t*)tid;
    int retval = pthread_join(*tid_c, NULL);
    printf("In joinit: tid = %d, retval = %d \n", *tid_c, retval);
    return NULL;
  }
  
  int main()
  {
    pthread_t thread1;
    pthread_t thread2;
  
    pthread_create(&amp;thread1, NULL, joinit, &amp;thread2);
    pthread_create(&amp;thread2, NULL, joinit, &amp;thread1);
  
    pthread_join(thread2, NULL);  
  
    return 0;
  }
  </code></pre>
  
  <p>But however, it says 'EINVAL' (invalid argument) because <code>thread2</code> is not yet specified when <code>pthread_create</code> for <code>thread1</code> is called.</p>
  
  <p>Any ideas?</p>