#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//線程處理函數(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;
}
本文標(biāo)題:[Linux線程]使用pthread_create函數(shù)的arg參數(shù)
分享地址:http://www.yijiale78.com/article16/pdssgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、動(dòng)態(tài)網(wǎng)站、網(wǎng)站營(yíng)銷(xiāo)、靜態(tài)網(wǎng)站、軟件開(kāi)發(fā)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)