pthreads et exceptions ne font pas bon ménages ?
Bonjour,
J'ai un léger soucis lorsque j'ai voulu faire cohabiter des threads et des exceptions (windows/pthreads/mingw).
J'arrive à obtenir l'erreur avec le code minimal suivant :
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <iostream>
#include <cassert>
#include <pthread.h>
#ifdef WIN32
/* MS-Windows */
#include <windows.h>
#define msleep(ms) Sleep(ms)
#else
/* unixoides */
#include <unistd.h>
#define msleep(ms) usleep((ms * 1000))
#endif
void * test(void * f)
{
for(int j=0; j<5; j++)
for(int i = 0; i<5;i++)
std::cerr<<"Thread numero : "<<std::endl;
std::cerr<<"Thread a fini"<<std::endl;
return NULL;
}
int main (int argc, char * argv[])
{
pthread_t thread1;
pthread_t thread2;
if(pthread_create(&thread1, NULL, test, NULL)!=0)
return 0;
if(pthread_create(&thread2, NULL, test, NULL)!=0)
return 0;
std::cerr<<"Démarrage try";
try
{
msleep(1000);
std::cerr<<"Lancement exception";
throw std::exception();
}
catch(std::exception &e)
{
std::cerr<<"IO FAILURE";
}
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
return 0;
} |
J'ai lu qu'il y avait des problèmes lorsque deux threads rencontraient des exceptions simultanément, mais pas dans ce cas.
Quelqu'un a déjà-t-il eu le problème et sait comment faire ?
J'ai lu quelque part qu'il fallait utiliser les options : --enable-__cxa_atexit et --enable-threads=posix, mais j'ai le sentiment que cela ne fonctionne que sous Unix car mon mingw ne reconnait pas ces options.
:merci: