營銷網(wǎng)站建設(shè)規(guī)劃淘寶指數(shù)查詢
- pthread_create 的第三個(gè)參數(shù),為函數(shù)指針,指向處理線程函數(shù)的地址。該函數(shù),要求為靜態(tài)函數(shù)。如果處理線程函數(shù)為類成員函數(shù)時(shí),需要將其設(shè)置為靜態(tài)成員函數(shù)。
- C++靜態(tài)成員函數(shù)訪問非靜態(tài)成員
https://blog.csdn.net/yueguangmuyu/article/details/118390764 - C++靜態(tài)成員函數(shù)訪問非靜態(tài)函數(shù)
函數(shù)定義
private:/*工作線程運(yùn)行的函數(shù),它不斷從工作隊(duì)列中取出任務(wù)并執(zhí)行之*/static void *worker(void *arg);void run();
調(diào)用
pthread_create(m_threads + i, NULL, worker, this)
通過void *arg指針接受任何類型的指針,再使用強(qiáng)制類型轉(zhuǎn)換運(yùn)算符創(chuàng)建一個(gè)新的實(shí)例
void *threadpool<T>::worker(void *arg)
{threadpool *pool = (threadpool *)arg;pool->run();return pool;
}
https://github1s.com/qinguoyi/TinyWebServer/blob/HEAD/threadpool/threadpool.h#L93