There are codes about pthread in C
Code:
1.#include <pthread.h>
2.#include <stdlib.h>
3.#include <unistd.h>
4.void *thread_function(void *arg) {  
5.    printf("Thread says hi!\n");    
6.  return NULL;
7.}
8.int main(void) {
9.  pthread_t mythread;
10.  if ( pthread_create( &mythread, NULL, thread_function, NULL) ) {
11.   printf("error creating thread.");
12.    abort();
13.  }
14.  if ( pthread_join ( mythread, NULL ) ) {
15.   printf("error joining thread.");
16.    abort();
17.  }
18.  exit(0);
19.}
After compiling and executing i get what i expect
Code:
red 327 % gcc -o thread.out thread.c -lpthread
red 328 % thread.out
Thread says hi!
red 329 %
However, if I delete the second statement at line 14 and after compiling and executing i get
Code:
red 329 % gcc -o thread.out thread.c -lpthread
red 330 % thread.out
red 331 %
My question is why the result is like this after deleting pthread_join(mythread,NULL) and what does pthread_join do.Thanks