bor061297
asked on
Threads
If I start a new thread with _beginthread(...)
do I have to terminate it before I exit application,
or it is automatically terminated?
do I have to terminate it before I exit application,
or it is automatically terminated?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am talking about Win32.
When I click 'X' application terminates, even if
i didn't closed all thread, but I am worried if
some thread stayed active after closing application.
When I click 'X' application terminates, even if
i didn't closed all thread, but I am worried if
some thread stayed active after closing application.
>> When I click 'X' application terminates, even if i didn't closed all thread
Closing an application with the 'X' sends a WM_CLOSE message to the main window. Closing the main window and exiting the message pump does not mecessarily mean that the process is no longer running.
Use the ExitProcess() API to exit all the threads of your process if you want to be sure.
Of course, the threads usually do something important at the time so it is better to notify them that the program is pending termination (by setting a global flag which they poll, for instance) and then WaitForMultipleObjects() on the threads.
Closing an application with the 'X' sends a WM_CLOSE message to the main window. Closing the main window and exiting the message pump does not mecessarily mean that the process is no longer running.
Use the ExitProcess() API to exit all the threads of your process if you want to be sure.
Of course, the threads usually do something important at the time so it is better to notify them that the program is pending termination (by setting a global flag which they poll, for instance) and then WaitForMultipleObjects() on the threads.
It sounds like Unix, which means I don't know, but in Windows the rule is that you don't have to, but you should.