title: pthread_join function crash
body: <p>There is a crash inside 'pthread_join' when main function calls it and before that the child thread already terminated. This is the backtrace from gdb:</p>
  
  <pre><code>Core was generated by `./bin/test'.
  Program terminated with signal SIGSEGV, Segmentation fault.
  #0  0xb76fb530 in __call_tls_dtors@plt () from /lib/libpthread.so.0
  (gdb) bt
  #0  0xb76fb530 in __call_tls_dtors@plt () from /lib/libpthread.so.0
  #1  0xb76fdd5a in start_thread (arg=0xb40fab40) at pthread_create.c:319
  #2  0xb762f74e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
  </code></pre>
  
  <p>The pthread activation function receives NULL argument and return NULL argument. I am clueless why I am seeing this crash consistently. </p>
  
  <p>Could somebody help what could be wrong in child thread activation function? I am using Fedora 20 and gcc version 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC)</p>
  
  <p>Skeleton of child activation function is below</p>
  
  <pre><code>void* testControl(void* param)
  {
     ...................
     return NULL;
  }
  </code></pre>
  
  <p>As the my code is huge I am giving here the code snippet which explains how I am creating child threads, their exits and termination.</p>
  
  <pre><code>unsigned long int rcThId1;  
  unsigned long int rcThId2;
  unsigned long int rcThId3;
  unsigned long int rcThId4;
  unsigned long int rcThId5;
  unsigned long int rcThId6;
  
  void* rcControl1(void* arg)
  {
    bool th_loop = true;
  
    while(th_loop)
    {
  
       /*Listen and receive the message on message queue*/
  
       ...........
       ..........
  
       switch(message_type)
       {
          ............
          ............
  
          case EXIT:
  
            th_loop = false;
            break;
  
          default:
            break;
       }
  
     }
  
     return NULL;
  
  }
  
  /*Activation functions for rcControl2 rcControl3 rcControl4
  
  rcControl5 rcControl6 similar to the defination of rcControl1*/
  
  int main(void)
  {
    pthread_create(&amp;rcThId1,NULL,rcControl1,NULL);
    pthread_create(&amp;rcThId2,NULL,rcControl2,NULL);
    pthread_create(&amp;rcThId3,NULL,rcControl3,NULL);
    pthread_create(&amp;rcThId4,NULL,rcControl4,NULL);
    pthread_create(&amp;rcThId5,NULL,rcControl5,NULL);
    pthread_create(&amp;rcThId6,NULL,rcControl6,NULL);
  
    ..............
    ..............
    /*Post EXIT event to Thread1*/
    /*Post EXIT event to Thread2*/
    /*Post EXIT event to Thread3*/
    /*Post EXIT event to Thread4*/
    /*Post EXIT event to Thread5*/
    /*Post EXIT event to Thread6*/
    /*By now all threads would have already exited */
  
    pthread_join(rcThId1, NULL);/*Inside this function crash is happening*/    
    pthread_join(rcThId2, NULL);
    pthread_join(rcThId3, NULL);
    pthread_join(rcThId4, NULL);
    pthread_join(rcThId5, NULL);
    pthread_join(rcThId6, NULL);
  
    return 0;
  }
  </code></pre>
  
  <p>Inside <code>pthread_join(rcThId1, NULL);</code> call the crash is happened.</p>
  
  <p>Thanks</p>