Say, if I have a thread ID, can I be assured that it will be unique (for as long the thread is running) per process or throughout the OS (among all logged in users)?
The thread ID is used by the operating system to identify processes and threads. The thread id is unique globally but the users can capture the thread handle of the process thread through this id.
The TID (as returned by the sys_gettid() system call) is unique across all threads on the system1, and for a single-threaded process the PID and TID are equal. This means that a TID will never clash with a PID from another process. Save this answer.
Thread IDs can be recycled. Your code is starting a thread and waiting for it to finish. There are never more then one (apart from the main-thread) running. Hence, you get the same ID.
Each process running in Windows is assigned a unique decimal number called the process ID (PID).
Yes, thread ID's and Process ID's on Windows are allocated from the same pool, so they will be unique. Once the thread or process ends however, the ID may be re-used by another thread or process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With