Thread Id and Thread Handle

来源:互联网 发布:张大奕淘宝店铺 编辑:程序博客网 时间:2024/04/30 13:36

关于Thread id和Thread handle的区别,这篇文章讲的很清楚:

http://hi.bccn.net/space-21499-do-blog-id-17530.html

简而言之,handle包含了访问权限的信息,使用handle来控制内核对象,而且一个内核对象可以对应多个handle。

而Id只是一个全局唯一的标识符。

 

两者之间的相互转换:

Handle -> Id:GetThreadId

Id -> Handle:OpenThread()

 

注意在Wince5.0及以下版本中没有OpenThread()这个函数,我的调查结果是可以用GetThreadId() 代替。

MSDN上说,GetCurrentThreadId(): returns the thread identifier, which is used as a handle of the calling thread.

看看CE5.0上CreateThread() 的实现:DoCreateThread() in private/winceos/coreos/nk/kernel/schedule.c, at the bottom of this method:

if (lpthid)
            *lpthid = (DWORD)hth;

所以看见thread id就是从thread handle转换来的,它俩一样一样的。