mardi 30 avril 2019

C++ pthread_join() causes segmentation fault

I am creating n POSIX threads and pushing them to a pthread_t vector. When I am joining them by iterating through the vector, I get a segmentation error. I checked and verified that the number of threads created is equal to the number of threads that I was trying to join. What may cause the segmentation fault? I will appreciate any help. Here is the sample:

std::vector<pthread_t> threadVector;

for (int i=0; i<inp1.size(); i++){
    pthread_t thread;
    threadVector.push_back(thread);
    int ii = pthread_create(&thread, NULL, mythread1, &(inp1[i]));
}

for (int i=0; i<inp2.size(); i++){
    pthread_t thread;
    threadVector.push_back(thread);
    int ii = pthread_create(&thread, NULL, mythread2, &(inp2[i]));
}

std::cerr<<inp1.size()+inp2.size()<<","<<threadVector.size()<<std::endl; 

for (auto& th : threadVector) 
    pthread_join(th, NULL);

Aucun commentaire:

Enregistrer un commentaire