Erreur glibc invalid pointeur
Bonjour à tous,
Je cherche à paralléliser l'exécution d'un programme sur un ensemble de fichier à l'aide de thread et d'un accès via mutex à la liste des fichiers à traité.
Mon programme fonctionne (les fichiers sont tous bien traité) mais me génère l'erreur suivante lorsque je le fais tourner avec plus d'un thread.
Si j'ai bien compris je libère deux fois un accès mémoire mais je ne vois pas lequel.
Erreur :
Code:
1 2 3 4 5 6 7
| *** glibc detected *** ./cppMutliThread: free(): invalid pointer: 0x00007fdab4f286e8 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7fdab92abb96]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_ZNSsD1Ev+0x23)[0x7fdab98a1c13]
./cppMutliThread[0x4013be]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fdab924e76d]
./cppMutliThread[0x4010a9] |
Mon programme:
main.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
#include <sstream>
#include <string>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <list>
#include <vector>
#include <dirent.h>
void *worker_thread(void *arg);
static pthread_mutex_t mutex_stock = PTHREAD_MUTEX_INITIALIZER;
using namespace std;
/*création de ma liste de commande contenant le nom du fichier à traité*/
pthread_t my_thread[NBPROC];
int id;
for(id = 1; id <= NBPROC; id++) {
int ret = pthread_create(&my_thread[id], NULL, &worker_thread, listeFichier);
if(ret != 0) {
printf("Error: pthread_create() failed\n");
exit(EXIT_FAILURE);
}
}
int toto;
for(toto=1;toto<=NBPROC;toto++)
{
pthread_join(my_thread[toto],NULL);
}
return EXIT_SUCCESS;
} |
La fonction utilisé par les threads
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
void *worker_thread(void *arg)
{
vector<string>* listeFichier=(vector<string>*)arg;
vector<string> test=*(vector<string>*)arg;
string* fichier;
while(1)
{
pthread_mutex_lock(&mutex_stock);
if(listeFichier->size()>0)
{
fichier=&listeFichier->back();
listeFichier->pop_back();
int retour = system((const char *)fichier->c_str());
if(retour!=0)
{
cout<<retour<<endl;
}
}
else
{
pthread_mutex_unlock(&mutex_stock);
return NULL;
}
}
return NULL;
} |
D'avance merci