Salut a tous,

J'essaye d'utiliser la librairie pthreads-win32 avec MinGW/MSYS sans success.... alors que ca fonctionne a merveille sous linux.

J'ai ecris un petit code test pour illustrer le probleme. Je n'ai sais pas si ca vient de ma machine ou si c'est mon code...
Dans mon code je fais appel a Python.h pour lancer l'interpreteur python a partir de mon code C, soit en mode 'normal' sans thread, soit dans un thread separe du main():

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
// compile under MingGW/MSYS with:
// gcc program.c -o program.exe -lpython25 -lpthreadGC2 
 
#include <stdio.h>
#include <Python.h>
#include <pthread.h>
 
int using_thread=0;
 
void *run_python_console(void *arg);
 
int main(int argc,char **argv){
 
//managing command line arguments
if(argc<2){fprintf(stdout,"this program needs arguments. 0 for sequential, 1 for multithreading\n");exit(1);}
using_thread = atoi(argv[1]);
if(using_thread!=0 && using_thread!=1){fprintf(stdout,"Unkown argument. Use 0 for sequential, 1 for multithreading\n");exit(1);}
 
 
//if running in sequential mode
if(using_thread==0){
   run_python_console("");
}
//if running in threads
else{
   pthread_t pth;
   pthread_create(&pth,NULL,run_python_console,"");
}
 
fprintf(stdout,"coucou!\n");fflush(stdout);
 
return 0;
}
 
void *run_python_console(void *arg)
{
 
   fprintf(stdout,"Python console loading.....\n");fflush(stdout);
 
   Py_Initialize();
 
	  fprintf(stdout,"interactive loop\n");fflush(stdout);
 
      PyRun_InteractiveLoop(stdin,"<stdin>");
 
  fprintf(stdout,"unloading python...\n");fflush(stdout);
  if(Py_IsInitialized()==1){Py_Finalize();}
 
 
return;
}
Si je lance 'program.exe 0', je vois le l'intrepreteur de python qui se lance...tous va bien.

Par-contre, si je lance 'program.exe 1', tout se passe comme si le thread n'a meme pas ete cree !

quelqu'un a une idee ?

Merci d'avance

David