pthread_self() in C with Example Last Updated : 28 Oct, 2019 Comments Improve Suggest changes 3 Likes Like Report 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. C // C program to demonstrate working of pthread_self() #include <stdio.h> #include <stdlib.h> #include <pthread.h> void* calls(void* ptr) { // using pthread_self() get current thread id printf("In function \nthread id = %d\n", pthread_self()); pthread_exit(NULL); return NULL; } int main() { pthread_t thread; // declare 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 Create Quiz Comment D Devanshu Agarwal 3 Improve D Devanshu Agarwal 3 Improve Article Tags : Misc C Language Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like