1)这篇文章的答案WaitForSingleObject : how to get handle from _beginthreadex说只有将 uintptr_t 返回的 _beginthreadex 转换为 HANDLE 类型才是合法的,那么将 uintptr_t 返回的 _beginthreadex 转换为 HANDLE 类型是否不安全?
2)我们在 32 位应用程序中进行了如下转换,看起来运行良好,当我将此应用程序转换为 64 位时会遇到任何问题吗? HANDLE 线程 = (HANDLE)_beginthread(checkThread, 0, &thrVal);
3) 是否值得将所有 _beginthread 调用转换为 _beginthreadex?
最佳答案
如果您想使用 Windows 同步 API,您需要一个由您控制的 HANDLE
。使用从 _beginthread
返回的 uintptr_t
无法安全地转换为 HANDLE
值以与同步 API 一起使用。 _beginthread, _beginthradex 的文档这里很清楚(强调我的):
You can also use the thread handle that's returned by _beginthreadex with the synchronization APIs, which you cannot do with _beginthread.
如果您不想依赖未记录的行为,并且需要 HANDLE
值与同步 API 一起使用,则必须使用 _beginthreadex
。
关于c++ - 将 _beginthread 返回的 uintptr_t 转换为 HANDLE 是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19438202/