Thread ID vs. Thread Handle

The ID is the unique numeric identifier of the thread running in the system. A thread handle, like any kernel object handle, can be seen as a special type of reference counted pointer to the kernel object.

So in kernel space there is an object of type THREAD with ID = 12345

And because you want to do something with the thread you have a pointer in your address space called a threadID with value 44.

Please note that different handles to the same kernel object have different values (two pointers to one object) and that kernel objects can have handles in more than one process.


Linux's pthread library does not, as far as I know, have a concept of a thread handle. pthread_create and other pthreads functions, return a thread ID.

Under Windows, the thread handle is different from the thread ID, in the same way that a file handle is different from a file name.

The thread handle is a token which allows you to do something with the thread (typically wait for it or kill it). Win32 has these tokens for lots of objects, and calls them HANDLE in general.

The token is essentially a pointer at the running (or stopped) thread and has a set of abilities associated with it, for example, you can have a handle which permits you to wait for, but not kill, a thread. In the same way, we can have a file handle which is read-only.

This level of indirection may or may not be useful, but it's the way Win32 does it, and it's broadly consistent with how it handles some other types of objects.


Thread IDs are progressive (ie, one after another), which you can traverse. Thread handles, like most handles in Windows, are actually pointers. You might, for example, set thread property bits by using the thread handle - but not thread id.