[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);}intmain(intargc,char*argv[]){inti;pthread_tthreadid;for(i=0;i<10;i++){if(pthread_create(&threadid,NULL,threaddeal,&i)!=0)//将i值作为参数传递{//返回值不为0则表明创建线程失败printf("创建线程失败.\n");exit(0);//退出}}pthread_exit(NULL);return0;}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。