How do I guarantee fast shutdown of my win32 app?

Use overlapped IO so that you’re always in control of the threads that are dealing with your I/O and can always stop them at any point; you either have them waiting on an IOCP and can post an application level shutdown code to it, OR you can wait on the event in your OVERLAPPED structure AND wait on your ‘all threads please shutdown now’ event as well.

In summary, avoid blocking calls that you can’t cancel.

If you can’t and you’re stuck in a blocking socket call doing IO then you could always just close the socket from the thread that has decided that it’s time to shut down and have the thread that’s doing IO always check the ‘shutdown now’ event before retrying…

Leave a Comment