linux多執行緒的總結

2021-06-27 22:18:10 字數 496 閱讀 2569

執行緒的函式: i

nt pthread_create(pthread_t *restrict tidp,const pthread_attr_t *restrict attr,

void *(*start_rtn)(void),void *restrict arg);

引數功能:

第乙個引數為指向執行緒識別符號的指標。

第二個引數用來設定執行緒屬性。

第三個引數是執行緒執行函式的起始位址。

第四個引數是執行函式的引數。

當建立執行緒成功時,函式返回0,若不為0則說明建立執行緒失敗,常見的錯誤返回**為eagain和einval。前者表示系統限制建立新的執行緒,例如執行緒數目過多了;後者表示第二個引數代表的執行緒屬性值非法.

pthread_create的用法:由於pthread庫不是linux系統預設的庫,所以在使用pthread_create建立執行緒時,需要在編譯中**-lpthread引數,eg:gcc -o test -lpthrea test.c

linux多執行緒的總結(pthread用法)

include int pthread create pthread t restrict tidp,const pthread attr t restrict attr,void start rtn void void restrict arg returns 0 if ok,error numb...

linux多執行緒的總結(pthread用法)

include int pthread create pthread t restrict tidp,const pthread attr t restrict attr,void start rtn void void restrict arg returns 0 if ok,error numb...

linux多執行緒的總結(pthread用法)

include int pthread create pthread t restrict tidp,const pthread attr t restrict attr,void start rtn void void restrict arg returns 0 if ok,error numb...