GetCurrentThread() returns pseudo handle, not the real handle.
来源:互联网 发布:大地彩票v6 源码 编辑:程序博客网 时间:2024/04/29 07:09
From: http://weseetips.com/tag/pseudo-handle/
For getting our thread handle, we usually call GetCurrentThread() api. But actually it returns a pseudo handle. A pseudo handle, is a special handle which represents the handle of current thread which uses it. Please see the following e.g. for more clarify.
1) Thread A gets its threadID by calling GetCurrentThread and Passed to Thread B.
2) Thread B needs to terminate Thread A. So it calls TerminateThread( handle passed by Thread A ).
3) But instead of terminating Thread A, Thread B will be terminated, because the handle passed by Thread A was pseudo and it will become Thread B’s handle when Thread B uses it.
Debug one GetCurrentThread() call and GetCurrentProcess() call and watch its return values. You can see what they returns are follows,
- GetCurrentThread() – 0xfffffffe
- GetCurrentProcess() – 0xffffffff
Ofcourse pseudo… isn’t it ?
For getting a real handle which represents your thread, create a duplicate handle by calling DuplicateHandle(). Please see the code block below.
- GetCurrentThread() returns pseudo handle, not the real handle.
- handle
- HANDLE
- handle
- Handle
- handle
- handle
- handle
- Handle
- Handle
- handle()
- handle
- Handle
- handle
- Handle the link event.
- Handle Classes: The Smart Pointer
- Handle Classes: The Smart Pointer
- error:The handle is invalid.
- 教你通透彻底理解:BFS和DFS优先搜索算法
- 使用递归 输出文件树
- 浅谈Javascript面向对象编程
- 登陆csdn 1000次
- 链表常用操作 (定义,创建,反转,合并,交叉)
- GetCurrentThread() returns pseudo handle, not the real handle.
- 【Android】提高Adapter的效率
- priority_queue例子
- 在VO中引用Controller层中的Session State的两种方法
- hdoj 1035(算是水题把)(屏蔽freopen)
- 莫让代码腐化:让营地比你来时更干净
- 项目管理: Maven 让事情变得简单--给您的下一个 Java 构建添加项目管理特性
- hdu1176免费馅饼
- Linuxx下printf格式符%d、%lld、%llx、%u等