今天看了一段代码,发现判断CreateThread返回值的时候是否为NULL,根据我的经验失败因该是INVALID_HANDLE_VALUE,NULL是等于0的 INVALID_HANDLE_VALUE是等于-1的。
然后我就怀疑起来了,查看了三个开源项目,三个开源项目里都是INVALID_HANDLE_VALUE为失败,且都是老外写的。再去微软MSDN查 If the function succeeds, the return value is a handle to the new thread. If the function fails, the return value is NULL. To get extended error information, call GetLastError. 很明显NULL才是失败的。那为什么会有INVALID_HANDLE_VALUE结果呢,个人怀疑是因为CreateThread返回句柄的原因。那到底信谁的呢?反正我是按照微软官方的。