[問題] 執行緒退出

看板C_and_CPP (C/C++)作者 (免洗)時間12年前 (2014/04/19 10:51), 12年前編輯推噓1(103)
留言4則, 3人參與, 最新討論串1/1
開發平台(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
tfn2 的pthread_clean_pop,是 cleanup
04/19 11:17, 1F

04/19 11:18, , 2F
另外還要 include <errno.h><unistd.h><string.h>
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
現在errno都已經用TLS在存了 沒有覆蓋問題
04/19 16:58, 3F

04/19 23:26, , 4F
謝謝樓上 我會再去了解一下
04/19 23:26, 4F
文章代碼(AID): #1JKUJ7Mr (C_and_CPP)
文章代碼(AID): #1JKUJ7Mr (C_and_CPP)