Search code examples
c++cmultithreadingwinsock2resource-cleanup

Unblock From GetQueuedCompletionStatus


During program termination, how do you unblock a thread that has been previously blocked with a call to GetQueuedCompletionStatus()?


Solution

  • You could post termination message to the IO completion port using PostQueuedCompletionStatus API call or simply close IOCP handle using CloseHandle.

    If a call to GetQueuedCompletionStatus fails because the completion port handle associated with it is closed while the call is outstanding, the function returns FALSE, *lpOverlapped will be NULL, and GetLastError will return ERROR_ABANDONED_WAIT_0.