[Linux线程]使用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)  //将i值作为参数传递
    {
      //返回值不为0则表明创建线程失败
      printf("创建线程失败.\n");
      exit(0);    //退出
    }
  }
  pthread_exit(NULL);
  return 0;
}

本文标题:[Linux线程]使用pthread_create函数的arg参数
分享地址:https://www.cdcxhl.com/article16/pdssgg.html

成都网站建设公司_创新互联,为您提供商城网站动态网站网站营销静态网站软件开发外贸建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

商城网站建设