【发布时间】:2017-05-05 02:03:21
【问题描述】:
如何将对象向量传递给 pthread_create 函数?
我有这个代码:
#define THREAD_NUMBER 1000
void* threadRoom (std::vector <Room*> &rooms){
some code here....
}
int main () {
std::vector <Room*> rooms;
std::vector <pthread_t> workers(THREAD_NUMBER);
pthread_create(&workers[0], NULL, threadRoom, &rooms);
return 0;
}
我收到以下错误:
error: invalid conversion from ‘void* (*)(std::vector<Room*>&)’ to ‘void* (*)(void*)’ [-fpermissive]
pthread_create(&worker[0], NULL, threadRoom, &rooms);
note: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
extern int pthread_create (pthread_t *__restrict __newthread
【问题讨论】:
-
您将指向
rooms的指针传递给pthread_create,但您的threadRoom函数需要引用。
标签: c++ multithreading vector pthreads parameter-passing