Hi,

What happen when exit system call is made from.

1) main () 2) task created with pthread_create.

I have written a same program as below which has a loop in main ().
When pthread_exit is uncommented. main is not exiting and running in
infinite loop.
but it halts when i comment pthread_exit. So, i would like to
understand what happens when exit is called and how does pthread_exit
is effecting the behavior.

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!\n", tid);
   //pthread_exit(NULL);
   exit(0);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t<NUM_THREADS; t++){
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   while (1);
   return 0;
}

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to