내 프로젝트에 문제가 있습니다. 오류 코드 3을 던졌습니다.pthread_join 오류 코드 3
방금 내가 한 일을 볼 수 있도록 제 코드를 추가합니다. main.cpp에 내가 스레드에 선언 한 다음 initRequestThreads (thread.h에) 스레드를 만들려면 보내십시오. main.cpp에서 주 프로세스가 기다릴 수있게합니다.
MAIN.CPP
pthread_t *requestersThreads = new pthread_t[Length_Tasks];
requestsPool->initRequestThreads(&requestersThreads);
void* status;
// wait for all requests threads
for(t=0; t<Length_Tasks; t++) {
rc = pthread_join(requestersThreads[t], &status);
if (rc) {
cout<<"ERROR; return code from pthread_join() is "<< rc <<endl;
exit(-1);
}
cout<<"Main: completed join with REQUEST thread " << t <<" having a status of "<<(long)status<<endl;
}
// wait for all resolvers threads
for(t=0; t<resolveThreadsAmount; t++) {
rc = pthread_join(reoslveThreads[t], &status);
if (rc) {
cout<<"ERROR; return code from pthread_join() is "<< rc <<endl;
exit(-1);
}
cout<<"Main: completed join with RESOLVER thread " << t <<" having a status of "<<(long)status<<endl;
}
delete[] tasks;
delete[] TaskQueueRequests;
delete[] TaskQueueResolves;
//delete[] requestersThreads;
//delete[] reoslveThreads;
pthread_mutex_destroy(&TaskQueueResolves_lock);
pthread_cond_destroy(&TaskQueueResolves_cond);
ThreadPool.h
void initRequestThreads(pthread_t **threads)
{
// add the attribute join for the threads
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
int rc;
cout << "DEBUG "<< __LINE__<<": numOfThreads:"<<numOfThreadsRequests<<endl;
for(long i = 0; i < numOfThreadsRequests; i++)
{
threads[i] = new pthread_t;
rc = pthread_create(&(*threads[i]), &attr, ThreadPool::OperationRequestThread, (void *)this); // create thread that get all the thread pool object(this) and preform OperationRequest function
if(rc)
{
cout <<"creating Request thread failed! Error code returned is:"+rc<<endl;
exit(-1);
}
cout << "DEBUG "<< __LINE__<<": Creating Request Thread #" << i+1 << "!\n";
}
pthread_attr_destroy(&attr);
}
오류 번호 (''EINVAL'', ....)에 대해''pthread_join''의 반환 값을 테스트 했습니까? 원시 오류 값 이상으로 도움이됩니다. 귀하의 코드는 C와 C++의 엉망입니다. (''T *''대신에''vector''를 사용하십시오 ...) – nefas