tidtable.c - 访问线程数据表
实现功能:
这个模块包含以下用于多线程数据支持的例程:- _mtinit = Initialize the mthread data初始化m线程数据
- _getptd = get the pointer to the per-thread data structure for the current thread获取指向当前线程的线程数据结构指针
- _freeptd = free up a per-thread data structure and its subordinate structures释放线程数据结构及其从属的结构
- __threadid = return thread ID for the current thread返回当前线程的ID
- __threadhandle = return pseudo-handle for the current thread返回当前线程的伪句柄
伪句柄
- 在使用很多函数的时候,我们都需要获得一个对象的句柄,而某些函数,如GetCurrentProcess() / GetCurrentThread() 返回的是伪句柄 pseudohandle。
- 所谓伪句柄,即指向当前线程或者进程的句柄,并不是真正意义上的句柄。它并不创建句柄,同时也不增加引用计数,因次调用CloseHandle()不作任何处理。
- 它本身就只指向调用它的主调进程或线程。会因为调用者的不同而改变,比如:调用者A使用一个伪句柄,这个句柄指向调用者A,而调用者A将该句柄传递给调用者X,则这个句柄就指向调用者X。
- 进程的伪句柄总是0xffffffff,而线程的伪句柄总是**0xfffffffe。
- 通过使用DuplicateHandle这个强大的函数,可以将伪句柄转换为真正的句柄。