I have a Windows service written in C++ that functions as a TCP server listening for incoming connections.
I initialized the server socket and put the accept
code in a separate thread. This will accept and process the incoming connections.
However, I also need to stop this thread in case the service receives the STOP signal. So I thought of creating an event object using CreateEvent
and waiting for it to be signaled. This waiting would happen in the thread that creates the accept thread. So I could use the TerminateThread
function to stop the accept thread when the STOP signal is received.
However, MSDN says that
TerminateThread is a dangerous function that should only be used in the most extreme cases.
How strictly should this be followed and is my approach correct? What could be another way of doing this?