#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參數
分享地址:http://vcdvsql.cn/article16/pdssgg.html
成都網站建設公司_創新互聯,為您提供商城網站、動態網站、網站營銷、靜態網站、軟件開發、外貿建站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯