Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are thread IDs unique per process or per computer?

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)?

like image 508
c00000fd Avatar asked Dec 10 '12 09:12

c00000fd


People also ask

Is thread ID unique?

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.

Are Linux thread IDs unique?

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.

Can threads have the same ID?

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.

Is process ID unique?

Each process running in Windows is assigned a unique decimal number called the process ID (PID).


1 Answers

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.

like image 134
parrowdice Avatar answered Sep 22 '22 06:09

parrowdice