先决条件:C语言中的多线程
语法:-pthread_t pthread_self(void); pthread_self()函数返回在其中调用它的线程的ID。
// C program to demonstrate working of pthread_self()
#include
#include
#include
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;
}
输出:
In function
thread id = 1
In main
thread id = 1
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。