Visualizza la versione completa : [c++] abort di un thread

07-10-2009, 15:06

su win32 creando un thread con la CreateThread lo si chiude con la closeHandle..

ma volessi abortirlo di cattiveria? come dovrei fare?

07-10-2009, 15:33

07-10-2009, 19:04
In ogni caso eviterei...

TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code. DLLs attached to the thread are not notified that the thread is terminating. The system frees the thread's initial stack.

Windows Server 2003 and Windows XP/2000: The target thread's initial stack is not freed, causing a resource leak.

TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:

If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.

07-10-2009, 20:45
Originariamente inviato da MItaly
In ogni caso eviterei...

Beh ... s ... ma la richiesta era quella ... :bh:

07-10-2009, 22:45
Certo, mi limitavo a metterlo in guardia. :)