所以我有一个结构如下:传递结构数组到在pthread_create
struct threadData{
string filename
int one;
int two;
};
,我创建了这些结构的一个这样的数组:
pthread_t threadID[5];
struct threadData *threadP;
threadP = new struct threadData[5];
然后我通过这一个线程函数结构数组如下:
for(int i = 0; i < 5; i++){
pthread_create(&threadID[i], NULL, threadFunction, (void *) threadP[i]);
}
这就是我的threadFunction写法:
void *threadFunction(void * threadP[]){
}
我已经尝试过各种东西,但我总能得到什么我传递是不正确的,我应该怎么做这个正确的,这样我可以在每个结构对象我通过访问和处理的变量中的错误在?我有一种感觉,我的语法在某处是错误的,因为我使用了一系列的结构体......我只是不知道错在哪里或是什么。任何帮助,将不胜感激!
它应该是'&threadP [i]'。就这样。 – 2012-10-20 01:10:14
为什么不使用std :: thread? –
或'boost :: thread'? – Recker