Locally Unique ID

Sometimes you need a locally unique identifier. For example, you may want to create a temporary file but there may have may instances of your code running, and you don't want any of them to conflict on the file name.

You can try with a random file name, and call CreateFile on it. If CreateFile returns that the file has already exist, you try with a new name. If the file name is random enough, the collision will be small.

Or, you can create something almost guarantee to be locally unique.

Time only moves forward. The current system time is a good candidate for it.

On any given time, there could be multiple processes running. You need to distinguish those processes. The process ID is the obvious choice.

On a running process, you need something to separate the potential multiple thread. Thread ID is a good fit.

So, Current System Time + Process ID + Thread ID is a very good candidate for such locally unique identifier.

But it is not perfect, because the Current System Time does not have enough precision. It is possible that within the smallest measurement of the system time, a process will exist, and a new process will start with the same Process ID as the old process (and the same Thread ID). But the chance is so rare that you may not need to worry about it.