thread.c
来自「操作系统实验」· C语言 代码 · 共 28 行
C
28 行
#include<stdlib.h>#include<stdio.h>
#include<pthread.h>
const int numThreads=4;//线程的数目
void *threadFunc(void *pArg)//线程调用的函数
{
int myNum=*((int*)pArg);
printf("Hello From Thread %d\n",myNum);
return 0;
}
int main()
{
pthread_t hThread[numThreads];
int tNum[numThreads]; int i;
for(i=0;i<numThreads;i++)
{
tNum[i]=i;
pthread_create(&hThread[i],NULL,threadFunc,&tNum[i]);//创建线程 pthread_join(hThread[i],NULL);//等待线程完成
} return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?