#include <stdlib.h>#include<pthread.h>#include<stdio.h>#include<sched.h>#include<errno.h>void*consumer (void*p) {Sleep (Ten);//This code, mainly for testing purposes, is plainly waiting until all threads have been created, in the output thread identifier printf ("(%lu)%lu\n", Pthread_self (),(* (unsigned long int* ) (p)); //Note This format pthread_exit (NULL); }intMainintargcChar*argv[]) {printf ("(%lu) \ n", Pthread_self ()); pthread_t T1;intI=1; intret; Do{ret=pthread_create (&t1,null,consumer, (void*) &t1); if(ret!=0) {printf ("Create failed,%d\n", ret); Exit (1); } I++; } while(i<=8); Sleep ( -); return 0 ;}/*[email protected] desktop]# gcc a.c-lpthread[[email protected] desktop]#./a.out (3079116480) (3047644016) 3005684592 (3037154160) 3005684592 (3058133872) 3005684592 (3026664304) 3005684592 (3016174448) 3005684592 (3005684592) 3005684592 //Note that the two values are the same! (3068623728) 3005684592 (3079113584) 3005684592[[email protected] desktop]#*/
based on this output, it makes me wonder, the pthread_self () function actually gets the thread identifier based on what!
What exactly does Pthread_self () get the thread identifier for????