On Windows NT-based operating systems, process and thread IDs happen always to be a multiple of four. Is this just a coincidence? Yes, it’s just a coincidence, and you shouldn’t rely on it since it is not part of the programming contract. For example, Windows 95 process and thread IDs were not always multiples of four. (By comparison, the reason that kernel handles are always a multiple of four is part of the specification and will be guaranteed for the foreseeable future.)
Process and thread IDs are multiples of four as a side-effect of code re-use. The same code the allocates kernel handles is also used to allocate process and thread IDs. Since kernel handles are a multiple of four, so too are process and thread IDs. This is an implementation detail, so don’t write code that relies on it. I’m just telling you to satify your curiosity.
0 comments