The following are some conclusions:
● Createthread () API is used to create a thread. The API returns the same thread handle and thread ID ). The thread handle has full access to create a thread object. When a thread is running, the thread ID uniquely identifies the thread at the system level.
● The ID uniquely identifies the thread in the Windows system.
● Handle is used to operate the thread. There can be multiple handle, and each handle can have different operation permissions. The values obtained from openthread in different processes are different.
● The thread ID is global, and its handle is partial to the process.
● This ID is valid only for the lifetime of the thread.
● Handle is a bridge between operating processes and threads between the OS and client. The OS has a form for maintaining handle, which contains the reference count and related attributes of handle, handle is the operating system that identifies processes and threads, but you can also use this to mark processes and threads and operate on them. The Operating System ID is used to mark processes and threads, it is globally unique, but the handle of the process thread can be obtained through this ID. The handle obtained multiple times is not necessarily the same. handle is the kernel object, and the ID does not seem to be. There is no function dedicated to creating the ID.
● ID is automatically generated by the operating system when createthread is used.
● The thread handle and ID are different.
In Windows, the thread ID is unique. That is to say, if two threads return the same ID, they must be the same thread. Otherwise, they must be different threads. The thread handle is not the only identifier of the thread. The thread handle is only used to access a 32-bit value of the thread. Although the same handle must identify the same thread, however, the same thread may have two opened handles. Therefore, the handle cannot be used to identify whether two threads are the same.