【发布时间】:2017-11-18 16:55:03
【问题描述】:
我正在努力
ThreadPool::ThreadPool(int num_workers) {
workers.reserve(num_workers);
for (int i = 0; i < num_workers; i++) {
pthread_create(&workers[i], NULL, threadLoop, NULL);
}
}
void* threadLoop (void*); 这是 threadLoop 声明,它是 ThreadPool 类的私有成员函数,当我编译时,我得到一个错误 invalid use of non-static member function 我试图将函数设为静态,但是它看不到在类中声明的其他变量.我该如何解决这个问题?
【问题讨论】:
-
使用 std::thread.
-
不幸的是我不得不使用pthread
-
不幸的是,您必须学习如何使用C API。
标签: c++ multithreading class pthreads