In linux c program, how to print thread id of a thread created by pthread library?
for ex: we can get pid of a process by
pthread_self() function will give the thread id of current thread.
pthread_self() function returns the Pthread handle of the calling thread. The pthread_self() function does NOT return the integral thread of the calling thread. You must use
pthread_getthreadid_np() to return an integral identifier for the thread.
pthread_id_np_t tid; tid = pthread_getthreadid_np();
is significantly faster than these calls, but provides the same behavior.
pthread_id_np_t tid; pthread_t self; self = pthread_self(); pthread_getunique_np(&self, &tid);