_beginthreadex() est plus sûre quand on utilise la CRT (et on l'utilise pratiquement toujours).
Il me semble qu'elle est déclarée dans <process.h>. Il suffira de consulter l'aide pour être sûr...
Version imprimable
_beginthreadex() est plus sûre quand on utilise la CRT (et on l'utilise pratiquement toujours).
Il me semble qu'elle est déclarée dans <process.h>. Il suffira de consulter l'aide pour être sûr...
Ok merci mais comment alors declarer ma fonction ?
-->Code:DWORD WINAPI lectureFichierGPS(LPVOID lpParam)
mais je crois pas...Code:UINT WINAPI lectureFichierGPS(LPVOID lpParam)
Tu ne crois pas, mais si je me souviens bien, c'est pourtant le cas... (UINT WINAPI est la même chose que unsigned int __stdcall, donc _beginthreadex() l'accepte sans problème).
Par contre, _beginthreadex() retourne un uintptr_t, que tu devras caster en HANDLE (avec un reinterpret_cast<> puisque tu es en C++)...
Oui mais je me prend un :
et puis le pData ne passe plus...Citation:
invalid conversion from `UINT (*)(void*)' to `void*'
Bizarre... Tu peux montrer ton code ?
Oui bien su, je ne peux rien te refuser ;) :
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 void listenPort() { PMYDATA pData; string fileName; int port = 1563, sinsize; WSADATA WSAData; WSAStartup(MAKEWORD(2,0), &WSAData); SOCKET sock; SOCKET csock; SOCKADDR_IN sin; SOCKADDR_IN csin; HANDLE hThread; sock = socket(AF_INET, SOCK_STREAM, 0); sin.sin_addr.s_addr = INADDR_ANY; sin.sin_family = AF_INET; sin.sin_port = htons(port); bind(sock, (SOCKADDR *)&sin, sizeof(sin)); listen(sock, 0); sinsize = sizeof(csin); do { OutputDebugString("Waiting for connection..."); if ((csock = accept(sock, (SOCKADDR *)&csin, &sinsize)) != INVALID_SOCKET) { OutputDebugString("Connection established !"); fileName = attenteInfos(1564, csock); closesocket(csock); } if (fileName != "NOP" && !fileName.empty()) { OutputDebugString("File received, current processing file..."); pData = (PMYDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MYDATA)); pData->fileNameLink = strdup(fileName.c_str()); OutputDebugString("Creating thread..."); hThread = _beginthreadex(lectureFichierGPS, 0, pData); //hThread = CreateThread(NULL, 0, lectureFichierGPS, pData, 0, NULL); OutputDebugString("Thread created !"); OutputDebugString("Closing handle..."); pData = NULL; CloseHandle(hThread); OutputDebugString("Handle closed !"); } else { OutputDebugString("File not received, same MD5 !"); } } while (1); closesocket(sock); WSACleanup(); }
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
60
61
62
63
64
65
66 UINT WINAPI lectureFichierGPS(LPVOID lpParam) { OutputDebugString("Thread launch !"); string nom, utilisateur, constructeur, model, osVersion, cpu, ram, fileName; int maxSofts, x = 1; PMYDATA pData; pData = (PMYDATA)lpParam; fileName = pData->fileNameLink; OutputDebugString("Reading and save file !"); c_inifile_init(fileName.c_str(), NULL); { { char *iniNom =c_inifile_get_string("MACHINE", "NOM", NULL); nom = iniNom; free(iniNom); char *iniUtilisateur = c_inifile_get_string("MACHINE", "UTILISATEUR", NULL); utilisateur = iniUtilisateur; free(iniUtilisateur); char *iniConstructeur = c_inifile_get_string("MACHINE", "CONSTRUCTEUR", NULL); constructeur = iniConstructeur; free(iniConstructeur); char *iniModel = c_inifile_get_string("MACHINE", "MODEL", NULL); model = iniModel; free(iniModel); char *iniOsVersion = c_inifile_get_string("MACHINE", "VERSION OS", NULL); osVersion = iniOsVersion; free(iniOsVersion); char *iniCpu = c_inifile_get_string("MACHINE", "CPU", NULL); cpu = iniCpu; free(iniCpu); char *iniRam = c_inifile_get_string("MACHINE", "RAM", NULL); ram = iniRam; free(iniRam); char *maxSoftsTmp = c_inifile_get_string("SOFTS", "TOTAL", NULL); maxSofts = strtol(maxSoftsTmp, NULL, 0); free(maxSoftsTmp); } string listSofts[maxSofts]; for (x=1 ; x<=maxSofts ; x++) { char ch[3]; sprintf(ch, "%d", x); char * iniStr = c_inifile_get_string("SOFTS", ch, NULL); listSofts[x-1] = iniStr; free(iniStr); } if (verifExistOracle(nom) == 1) suppExistOracle(nom); if (insertDbOracleInfosDiv(nom, utilisateur, constructeur, model, osVersion, cpu, ram) != 0) OutputDebugString("Erreur lors de l'enregistrement dans la BDD Oracle \"insertDbOracleInfosDiv()\""); if (insertDbOracleSofts(nom, listSofts, maxSofts) != 0) OutputDebugString("Erreur lors de l'enregistrement dans la BDD Oracle \"insertDbOracleSofts()\""); } c_inifile_close(); free(pData->fileNameLink); pData->fileNameLink=NULL; HeapFree(GetProcessHeap(), 0, pData); OutputDebugString("Thread finished !"); return 0; }
Code:UINT WINAPI lectureFichierGPS(LPVOID lpParam);
Tu sembles confondre les prototypes de _beginthread() et _beginthreadex()...
Et hop encore une boulette ! :sm:
Ok ça ressemble plus à ça maintenant :
Et dans le thread j'ai rajouter :Code:
1
2 unsigned threadID; hThread = (HANDLE)_beginthreadex( NULL, 0, &lectureFichierGPS, pData, 0, &threadID );
Par contre je ne comprend pas cette dernière fonction, msdn me dit :Code:_endthreadex(0);
Ok je veux bien moi je suis pas difficile, mais alors ce qui suis cette fonction n'est pas exécuté, pourtant je dois bien faire un return x; moi... je pige pas là, si je fait le return avant le _endthreadex() ne sera pa executé non?Citation:
Terminates a thread created by _beginthread or _beginthreadex, respectively.
Tu n'es pas obligé de mettre un _endthreadex(), puisque ta fonction de thread se termine naturellement.
En fait, généralement, le seul endroit où l'on a à mettre ExitThread() ou _endthreadex(), c'est à la fin du main(), pour empêcher que le retour du main() tue tous les autres threads.
Ha ok grand merci! je vois demain si ça améliore mon problème de plantage et je vous tiens au courant !
T'es au courant que toute fuite de ressource (en particulier de mémoire) est strictement impossible, même face à des exceptions, si tu te restreints à l'idiome de programmation de base du C++, le RAII ?
heu...
Bonjour tous le monde,
Alors, le logiciel ne plante plus sous le debugger mais toujours des fuites de mémoires... je n'arrive pas à trouver d'où ça peut venir et je ne vois pas comment utiliser MemProof pour m'aider...
Peut-être que la fuite est ailleurs dans ton code?
Bon aller zou, je balance mon code : http://partage.stass.eu/public/serveur.rar
Salut spoutspout !
Je voulais savoir si tu avais eu le temps de jeter un oeil à mon code...
Franchement je sais plus quoi faire, j'ai beau le relire je ne vois plus rien...