Difference between thread handle and thread ID

Source: Internet
Author: User
Difference between thread ID and thread handle (reproduced)

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.