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

看板C_and_CPP (C/C++)作者 (zabby)時間16年前 (2010/03/21 20:12), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/2 (看更多)
遇到的問題 : 小弟想於windows環境下(VC6.0) 使用pthread實作多執行序 小弟將書上寫的code key in並執行 結果發生error C2664: 'pthread_create' : cannot convert parameter 3 from 'void *' to 'void *(__cdecl *)(void *)' Conversion from 'void*' to pointer to non-'void' requires an explicit cast 開發平台: VC++ 有問題的code: #include<stdio.h> #include<pthread.h> #include<stdlib.h> void do_one_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) { 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)++; } } 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)++; } } 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); } 補充說明:小弟不才,若想於VC下使用pthread語法,是只要將.DLL,.lib,.h 分別加入至相對應路徑中就可以work嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.135.11.124

03/21 20:15, , 1F
void do_one_thing(int *); <---要有回傳值,而且是pointer
03/21 20:15, 1F

03/22 05:14, , 2F
你的補充說明部分是對的!
03/22 05:14, 2F
文章代碼(AID): #1BfWqdsQ (C_and_CPP)
文章代碼(AID): #1BfWqdsQ (C_and_CPP)