MSDN says
If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.
The cod
Closing a handle while the handle is being waited on can also cause undefined behaviour.