- 论坛徽章:
- 0
|
看看下面这段,是否有帮助。
Never terminate the thread from outside the thread. Always terminate the thread from within the thread itself. If the thread isn't allowed to terminate itself, it will continue to consume resources even after the app is closed. Resources being memory for stack space and thread local storage, objects that are created by the thread, file buffers, etc.
Your thread will typically be running in a loop. If it's not, it will terminate automatically when it hits a return statement in the thread function or at the end of the thread function.
While looping in the thread function there are a couple of things you can do.
1. Periodically check the status of a flag variable that indicates to exit the thread (The flag can be set externally to the thread itself), and exit the loop once the flag is set.
2. Periodically check for an event to have occurred using one of the wait functions. |
|