На главную

On-line справка по Win32 API

Написать письмо
БЕСПЛАТНАЯ ежедневная online лотерея! Выигрывай каждый день БЕСПЛАТНО!
Список всех статей A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z | Скачать Вниз

TerminateThread



The TerminateThread function terminates a thread.

BOOL TerminateThread(

HANDLE hThread, // handle to the thread
DWORD dwExitCode // exit code for the thread
);


Parameters

hThread

Identifies the thread to terminate.
Windows NT: The handle must have THREAD_TERMINATE access. For more information, see Thread Objects.

dwExitCode

Specifies the exit code for the thread. Use the GetExitCodeThread function to retrieve a thread's exit value.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating.
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 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.



A thread cannot protect itself against TerminateThread, other than by controlling access to its handles. The thread handle returned by the CreateThread and CreateProcess functions has THREAD_TERMINATE access, so any caller holding one of these handles can terminate your thread.
If the target thread is the last thread of a process when this function is called, the thread's process is also terminated.
The state of the thread object becomes signaled, releasing any other threads that had been waiting for the thread to terminate. The thread's termination status changes from STILL_ACTIVE to the value of the dwExitCode parameter.

Terminating a thread does not necessarily remove the thread object from the system. A thread object is deleted when the last thread handle is closed.

See Also

CreateProcess, CreateThread, ExitThread, GetExitCodeThread


Пригласи друзей и счет твоего мобильника всегда будет положительным!
Предыдущая статья
 
Сайт Народ.Ру Интернет
Следующая статья
Пригласи друзей и счет твоего мобильника всегда будет положительным!

TerminateThread



Функция TerminateThread завершает резьбу.

BOOL TerminateThread(

РУЧКА hThread, // оперируется в выходной код резьбы DWORD dwExitCode // для резьбы
);


Параметры

hThread

Идентифицирует резьбу, чтобы завершаться.
Окно NT: ручка должна иметь доступ THREAD_TERMINATE. Более подробно, видьте как Резьба Возражала.

dwExitCode

Определяет выходной код для резьбы. Используйте функцию GetExitCodeThread, чтобы извлекать выходную величину резьбы.



Обратные Величины

Если функция добивается успеха, обратная величина ненулевая.
Если функция терпит неудачу, обратная величина нулевая. Для того, чтобы расширять информацию ошибки, назовите GetLastError.

Замечания

TerminateThread ИСПОЛЬЗОВАН, чтобы вызывать резьбу, чтобы выходить. Когда это происходит, целевая резьба не имеет шанс, чтобы выполнять любого пользователя-режима кода и начальный стек не освобожден. DLLs ПРИЛОЖЕННЫЙ к резьбе не извещены, что резьба завершает.
TerminateThread - опасная функция, которая должна только использована в крайних случаях. Вы должны называть TerminateThread только если Вы знаете точно, которым целевая резьба делает, и Вы управляете всем кодом, который целевая резьба могла бы возможно работать на момент завершения. Например, TerminateThread может закончиться следующими проблемами:

Если целевая резьба обладает критической секцией, критическая секция не будет выпущена.
Если целевая резьба выполняет определенные kernel32 вызовы когда она расторгнутая, kernel32 состояние для процесса резьбы могло быть противоречивым.
Если целевая резьба манипулирует глобальным состоянием коллективного DLL, состояние DLL могло бы быть уничтожено, влияя на другие пользователей DLL.



Резьба не может защитить себя против TerminateThread, кроме управляя доступом к своим ручкам. Ручка резьбы возвращалась CreateThread и функции CreateProcess имеют доступ THREAD_TERMINATE, так что любой вызывающий оператор, удерживающий одну из этих ручек может завершить вашу резьбу.
Если целевая резьба является последней резьбой процесса когда эта функция названа, процесс резьбы также завершен.
Состояние объекта резьбы становится сигнальным, выпуская любую другую резьбу, которая ждала резьбу, чтобы завершаться. Статус завершения резьбы заменяет с STILL_ACTIVE в величину параметра dwExitCode.

Завершение резьбы обязательно не удаляет объект резьбы из системы. Объект резьбы удален когда последняя ручка резьбы закрыта.

Смотри Также

CreateProcess, CreateThread, ExitThread, GetExitCodeThread


Вверх Version 1.3, Oct 26 2010 © 2007, 2010, mrhx Вверх
 mrhx software  Русский перевод OpenGL  Русский перевод Win32 API
 
Используются технологии uCoz