[問題] 執行緒退出

作者: WashFreeID (免洗)   2014-04-19 10:51:47
開發平台(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):
自己基礎很差
不太會要怎樣讓它編譯過
感謝各位大大
作者: asilzheng (asil)   2014-04-19 11:17:00
tfn2 的pthread_clean_pop,是 cleanup另外還要 include <errno.h><unistd.h><string.h>
作者: ah7675 (阿毛)   2014-04-19 16:58:00
現在errno都已經用TLS在存了 沒有覆蓋問題
作者: WashFreeID (免洗)   2014-04-19 23:26:00
謝謝樓上 我會再去了解一下

Links booklink

Contact Us: admin [ a t ] ucptt.com