#include
#include
#include
//線程處理函數(shù)
void *threaddeal(void *arg)
{
printf("%d\n",*((int *)arg)); //傳遞線程的參數(shù)
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值作為參數(shù)傳遞
{
//返回值不為0則表明創(chuàng)建線程失敗
printf("創(chuàng)建線程失敗.\n");
exit(0); //退出
}
}
pthread_exit(NULL);
return 0;
}
網(wǎng)頁名稱:[Linux線程]使用pthread_create函數(shù)的arg參數(shù)
轉(zhuǎn)載來源:
http://weahome.cn/article/pdssgg.html