国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

15.多線程——線程基本函數(shù)

2023-06-25 22:08 作者:M青春永不言棄  | 我要投稿

gcc??xxx.c -o xxx -lpthread

???怎么樣創(chuàng)建一個線程。

???線程創(chuàng)建函數(shù)

???函數(shù)功能:創(chuàng)建一個線程

???函數(shù)原型:int pthread_create(pthread_t *thread, const pthread_attr_t *attr,

??????????????????????????void *(*start_routine) (void *), void *arg)

???函數(shù)頭文件:#include <pthread.h>

???函數(shù)參數(shù):thread:他就是保存線程的id

?????????????attr:線程的屬性,一般填寫NULL

?????????????start_routine:他就是你要創(chuàng)建的線程的入口函數(shù)

?????????????arg:他就是你給線程函數(shù)傳遞的參數(shù)

???函數(shù)返回值:成功返回0?失敗返回不同的數(shù)。

?

?

???函數(shù)功能:線程的正常退出

???函數(shù)原型:void pthread_exit(void *retval)

???函數(shù)頭文件:#include <pthread.h>

???函數(shù)參數(shù):retval:一般填寫NULL

???函數(shù)返回值:無

?

?

???函數(shù)功能:等待指定的線程退出

???函數(shù)原型:int pthread_join(pthread_t thread, void **value_ptr);

???函數(shù)頭文件:#include <pthread.h>

???函數(shù)參數(shù):thread:你要等待退出的線程id

?????????????value_ptr:一般是線程退出的狀態(tài),一般寫NULL

???函數(shù)返回值:成功返回0?失敗返回對應(yīng)的數(shù)

?

?

???函數(shù)功能:取消一個正在運(yùn)行的線程

???函數(shù)原型:int pthread_cancel(pthread_t thread);

???函數(shù)頭文件:#include <pthread.h>

???函數(shù)參數(shù):thread:就是你要取消那個線程的id

???函數(shù)返回值:成功返回0?失敗返回對應(yīng)的數(shù)

?

???這兩個函數(shù)是配對使用的

???函數(shù)功能:線程清理函數(shù)

???函數(shù)原型:

?????????????void pthread_cleanup_pop(int execute);//決定了是否執(zhí)行注冊的清理函數(shù)

?????????????void pthread_cleanup_push(void (*routine)(void*), void *arg);//注冊你要清理的函數(shù)。

?

???函數(shù)頭文件:#include <pthread.h>

???函數(shù)參數(shù):execute:0代表不執(zhí)行清理函數(shù),其他的都代表執(zhí)行清理函數(shù)

?????????????routine:注冊的清理函數(shù)

?????????????arg:給清理函數(shù)傳遞的參數(shù)

???函數(shù)返回值:無

???注意:這里的函數(shù)他遵循咱們的棧的操作,先進(jìn)后出




15.多線程——線程基本函數(shù)的評論 (共 條)

分享到微博請遵守國家法律
乐业县| 柳江县| 东山县| 南和县| 阆中市| 宣汉县| 固安县| 玉门市| 霍城县| 枣庄市| 清丰县| 奉节县| 抚顺县| 昌黎县| 托里县| 龙海市| 漯河市| 霍林郭勒市| 赣州市| 肥西县| 阿尔山市| 忻州市| 西乌珠穆沁旗| 宁化县| 和平区| 陆良县| 繁峙县| 祥云县| 扎兰屯市| 鄂温| 改则县| 微山县| 托克逊县| 多伦县| 德清县| 邳州市| 大港区| 台前县| 伊金霍洛旗| 扬中市| 乐业县|