[問題] pthread_create成功但function沒跑

看板C_and_CPP作者 (鴆羅)時間12年前 (2013/10/29 23:14), 編輯推噓1(103)
留言4則, 4人參與, 最新討論串1/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Win7上用VirtualBox跑的Ubuntu 13.10 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) pthread.h 問題(Question): #include<pthread.h> ... void* function( void* ); #define thread_num 4 int main(){ pthread_t *pt; unsigned long long num; pt = new pthread_t[thread_num]; for( int z = 0 ; z < thread_num ; z++ ) pthread_create( &pt[z] , NULL , function , (void*) num ); ※我試過在function前面+"&"也不行 ... } void* function( void* t ){ printf("QQ\n"); unsigned long long times = (unsigned long long) t; ... } pthread_create的回傳值是0 但是印不出"QQ" 所以thread有create但是沒有跑進function 請問為什麼OTL -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.94.144

10/30 00:06, , 1F
flush試試看
10/30 00:06, 1F

10/30 00:14, , 2F
不要再 flush 了... XD
10/30 00:14, 2F

10/30 01:01, , 3F
以解決 加了thread_join就好了~
10/30 01:01, 3F

10/30 23:19, , 4F
應該是main死太快的緣故
10/30 23:19, 4F
文章代碼(AID): #1IRz3Nia (C_and_CPP)
文章代碼(AID): #1IRz3Nia (C_and_CPP)