[問題] 執行緒退出
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
linux gcc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
王者歸來linux C書裡面的範例 15-7
(這本真的錯誤很多)
雖然書上寫 用-lpthread
但都沒辦法過 全部改用-pthread
餵入的資料(Input):
預期的正確結果(Expected Output):
the second thread
No . 2 clean-up procdure
.....
錯誤結果(Wrong Output):
cleanup.c:43:1: error: expected ‘while’ before ‘void’
void *tfn3(void *arg)
^
cleanup.c:84:36: error: ‘tfn3’ undeclared (first use in this function)
err = pthread_create(&tid3, NULL, tfn3, NULL);
cleanup.c:84:36: note: each undeclared identifier is reported only once for each function it appears in
cleanup.c:86:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("cant create thread %s\n", strerror(err));
^
cleanup.c: In function ‘tfn2’:
cleanup.c:96:1: error: expected declaration or statement at end of input
}
^
cleanup.c:96:1: error: expected declaration or statement at end of input
程式碼(Code):(請善用置底文網頁, 記得排版)
https://github.com/hsuanchenli/C/blob/master/cleanup.c
補充說明(Supplement):
自己基礎很差
不太會要怎樣讓它編譯過
感謝各位大大
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.255.235.160
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1397875911.A.5B5.html
推
04/19 11:17, , 1F
04/19 11:17, 1F
→
04/19 11:18, , 2F
04/19 11:18, 2F
感謝 原來是少打up
不過這三個不用include 就ok了
書上有寫說因執行緒是隨意存取程序的環境變數 多個執行緒出錯
會使errno值被覆蓋 只會檢查到最後一個出錯thread的出錯原因
所以不設定errno
※ 編輯: WashFreeID (111.255.235.160), 04/19/2014 11:38:31
→
04/19 16:58, , 3F
04/19 16:58, 3F
→
04/19 23:26, , 4F
04/19 23:26, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章