2
我正在嘗試動態創建pthread並面對變量尋址中的問題。能否請你告訴的地址應如何訪問創建動態pthread_t時出錯
int main (int argc, char *argv[])
{
pthread_t *threads;
int rc, numberOfThreads;
long t;
cout<<"Number of Threads = ";
cin>>numberOfThreads;
cout<<endl;
threads =(pthread_t*) malloc(numberOfThreads*sizeof(pthread_t));
for(t=0; t<numberOfThreads; t++){
printf("In main: creating thread %ld\n", t);
// **ERROR ON BELOW LINE**
rc = pthread_create((pthread_t)&(threads+numberOfThreads), NULL, FunctionForThread, (void *)t);
(void) pthread_join(threads[t], NULL);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
/* Last thing that main() should do */
pthread_exit(NULL);
}
錯誤:lvalue required as unary ‘&’ operand
什麼是錯誤? –
你可能想要選擇一種語言。如果你選擇C++,你可以使用'std :: thread',這很容易。 – MSalters