fork download
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <errno.h>
  4. #define NTHREADS 5
  5. void *thread_function(void *);
  6.  
  7. int main()
  8. {
  9. pthread_t thread_id[NTHREADS];
  10. int i, j;
  11.  
  12. for(i=0; i < NTHREADS; i++)
  13. {
  14. pthread_create( &thread_id[i], NULL, thread_function, NULL );
  15. }
  16.  
  17. for(j=0; j < NTHREADS; j++)
  18. {
  19. pthread_join( thread_id[j], NULL);
  20. }
  21. return 0;
  22. }
  23.  
  24. void *thread_function(void *dummyPtr)
  25. {
  26. printf("Thread number %ld addr(errno):%p\n", pthread_self(), &errno);
  27. }
Success #stdin #stdout 0s 4184KB
stdin
Standard input is empty
stdout
Thread number 47663953913600 addr(errno):0x2b59a10aa680
Thread number 47663951812352 addr(errno):0x2b59a0ea9680
Thread number 47663949711104 addr(errno):0x2b59a0ca8680
Thread number 47663947609856 addr(errno):0x2b59a0aa7680
Thread number 47663945508608 addr(errno):0x2b59a08a6680