Handling Errors in Multithread Programs

Use the GetLastError function to obtain error information if any of the multithreading routines returns an error code. Remember that it returns the error code of the last error, not necessarily the error status of the last call.

Error codes are 32-bit values. Bit 29 is reserved for application-defined error codes. You can set this bit and use SetLastError if you are creating your own dynamic-link library, to emulate Win32 API behavior. Win32 functions only call SetLastError when they fail, not when they succeed.

The last error code value is kept in Thread Local Storage, so that multiple threads do not overwrite each other's values.