Como terminar um segmento suspenso dentro de uma dll corretamente?
Oi pessoal,
Eu tenho uma biblioteca de terceiros que contém um erro. Quando eu chamo uma função, ela pode travar. A função de biblioteca é chamada dentro de uma dll. Eu decidi mover a chamada para o fio e esperar por algum tempo. Se o encadeamento terminar, então OK. Se não - eu deveria terminar obrigatório.
O exemplo simplificado aqui:
<code>unsigned Counter = 0; void f() { HANDLE hThread; unsigned threadID; // Create the second thread. hThread = (HANDLE)_beginthreadex( NULL, 0, DoSomething, NULL, 0, &threadID ); if (WAIT_TIMEOUT == WaitForSingleObject( hThread, 5000 )) { TerminateThread(hThread, 1); wcout << L"Process is Timed Out"; } else { wcout << L"Process is Ended OK"; } CloseHandle(hThread); wcout << Counter; } unsigned int _stdcall DoSomething( void * /*dummy*/ ) { while (1) { ++Counter; } _endthreadex( 0 ); return 0; } </code>
A questão
oTerminateThread () função não é recomendado para ligar.Como mencionei antes, o encadeamento está sendo executadodentro de uma dll. Se eu terminar o tópico usandoTerminateThread () minha dll não descarregaria usandoFreeLibrary () ou até mesmoFreeLibraryAndExitThread (). Ambas as funções trava.Como encerrar o tópico e manterFreeLibrary () trabalhando?
Obrigado.