pthread_self() in C with Example
Prerequisite : Multithreading in C
Syntax :- pthread_t pthread_self(void);
The pthread_self() function returns the ID of the thread in which it is invoked.
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void * calls( void * ptr)
{
printf ( "In function \nthread id = %d\n" , pthread_self());
pthread_exit(NULL);
return NULL;
}
int main()
{
pthread_t thread ;
pthread_create(& thread , NULL, calls, NULL);
printf ( "In main \nthread id = %d\n" , thread );
pthread_join( thread , NULL);
return 0;
}
|
Output:
In function
thread id = 1
In main
thread id = 1
Last Updated :
28 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...