Re: [問題] 關於新手想於 VC6.0 使用 pthread

看板C_and_CPP (C/C++)作者 (ㄚ隆)時間16年前 (2010/03/22 05:14), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《zabby (zabby)》之銘言: : #include<stdio.h> : #include<pthread.h> : #include<stdlib.h> : void do_one_thing(int *); => void *do_one_thing(int *); : void do_another_thing(int *); => void *do_another_thing(int *); : void do_wrap_up(int,int); : int r1=0,r2=0; : void main() : { : pthread_t thread_1,thread_2; : pthread_create(&thread_1 , NULL , (void *) do_one_thing , (void *) &r1); : pthread_create(&thread_2 , NULL , (void *) do_another_thing ,(void *) &r2); : // do_one_thing(&r1); : // do_another_thing(&r2); : pthread_join(thread_1,NULL); : pthread_join(thread_2,NULL); : do_wrap_up(r1,r2); : } : void do_one_thing(int *pnum_times) void *do_one_thing(int *pnum_times); : { : int i,j,x; : for(i=0;i<4;i++) : { : printf("doing one thing\n"); : for(j=0;j<100000;j++) : x=x+i; : (*pnum_times)++; : } return NULL; : } : void do_another_thing(int *pnum_times) => void *do_another_thing(int *pnum_times) : { : int i,j,x; : for(i=0;i<4;i++) : { : printf("doing another\n"); : for(j=0;j<10000;j++) : x=x+i; : (*pnum_times)++; : } return NULL; : } : void do_wrap_up(int one_times,int another_times) : { : int total; : total = one_times+another_times; : printf("ALL done,one thing %d,another %d \nfor a total of %d\n", : one_times,another_times,total); : } 以上我做的修改部分你試試吧! :) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.104.196.232
文章代碼(AID): #1BfemRpW (C_and_CPP)
文章代碼(AID): #1BfemRpW (C_and_CPP)