[MSDN]线程结束时。。。
来源:互联网 发布:民营企业并购数据统计 编辑:程序博客网 时间:2024/05/18 03:09
Terminating a thread has the following results:
- Any resources owned by the thread, such as windows and hooks, are freed.
- The thread exit code is set.
- The thread object is signaled.
- If the thread is the only active thread in the process, the process is terminated. For more information, see Terminating a Process.
The GetExitCodeThread function returns the termination status of a thread. While a thread is executing, its termination status is STILL_ACTIVE. When a thread terminates, its termination status changes from STILL_ACTIVE to the exit code of the thread.
When a thread terminates, the state of the thread object changes to signaled, releasing any other threads that had been waiting for the thread to terminate. For more about synchronization, see Synchronizing Execution of Multiple Threads.
When a thread terminates, its thread object is not freed until all open handles to the thread are closed.
How Threads are Terminated
A thread executes until one of the following events occurs:
- The thread calls the ExitThread function.
- Any thread of the process calls the ExitProcess function.
- The thread function returns.
- Any thread calls the TerminateThread function with a handle to the thread.
- Any thread calls the TerminateProcess function with a handle to the process.
The exit code for a thread is either the value specified in the call to ExitThread, ExitProcess, TerminateThread, or TerminateProcess, or the value returned by the thread function.
If a thread is terminated by ExitThread, the system calls the entry-point function of each attached DLL with a value indicating that the thread is detaching from the DLL (unless you call the DisableThreadLibraryCalls function). If a thread is terminated by ExitProcess, the DLL entry-point functions are invoked once, to indicate that the process is detaching. DLLs are not notified when a thread is terminated by TerminateThread or TerminateProcess. For more information about DLLs, see Dynamic-Link Libraries.
The TerminateThread and TerminateProcess functions should be used only in extreme circumstances, since they do not allow threads to clean up, do not notify attached DLLs, and do not free the initial stack. In addition, handles to objects owned by the thread are not closed until the process terminates. The following steps provide a better solution:
- Create an event object using the CreateEvent function.
- Create the threads.
- Each thread monitors the event state by calling the WaitForSingleObject function. Use a wait time-out interval of zero.
- Each thread terminates its own execution when the event is set to the signaled state (WaitForSingleObject returns WAIT_OBJECT_0).
- [MSDN]线程结束时。。。
- [MSDN]线程结束时。。。
- 父线程结束时如何自动结束子线程
- 线程结束
- 结束线程
- 创建线程(From MSDN)
- msdn线程说明收藏
- msdn之多线程
- JavaFX 程序退出时结束子线程
- C#UI线程产生的子线程如何在UI结束时,干净的结束
- 等待指定线程结束
- 在外部结束线程
- 如何结束线程?
- 等待线程结束
- C# 线程结束方法
- 强制结束一个线程
- 结束线程方法
- 如何结束线程
- C#打包应用程序
- PIC16F87X单片机中断系统应用须关注的问题
- 【C/C++语言入门篇】-- 基本数据类型
- 这里真好
- [MSDN]线程结束时。。。
- [MSDN]线程结束时。。。
- flex手写识别
- 我的文章
- 开机后显示无法定位程序输入点于动态链接上(定位程序输入点_except_handler4_common于动态链接msvcrt.dll上)
- 数据库优化系列(转)
- 安装 phpmyadmin出现session无法创建问题
- php学习笔记(四)之发送邮件02 详细操作
- oracle表空间操作简单介绍
- Wince音频驱动(1)