1003使用pthread_create函数循环建立5个线程,而后每次在建立线程时将当前循环计数器的

/*ide

  • 编写一个程序,使用pthread_create函数循环建立5个线程,而后每次在
  • 建立线程时将当前循环计数器的值经过pthread_create函数的arg参数传递
  • 给新线程,在线程中打印输出该计数器的值。
    */

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>函数

void threaddeal(void arg)
{
printf("%d\n",((int )arg));
pthread_exit(NULL);
}线程

int main(int argc, char *argv[])
{
int i;
pthread_t threadid;
for(i=0;i<10;i++)
{
if(pthread_create(&threadid,NULL,threaddeal,&i)!=0)
{
printf("thread create is failed!\n");
exit(0);
}
}
pthread_exit(NULL);
return 0;
}it

相关文章
相关标签/搜索