| | |
- luid()
- Generate an ID which should be globally unique.
This only works if gethostname() returns an unique name. This usually is true to a certain degree if you
use your machine in an NIS/NFS configuration. So this function is mainly usefull to generate unique
filenames for NFS-shared filesystems.
So this is very well suited for generationg IDs in a setup where you controll all the machines and thus
hostnames.
- unique_machine32()
- Generate an ID which has a low probability of repeating on this machine.
What goes where:
PP ^
TTtt ^
c
So the first byte is an combination of a counter (c) and the first byte of the least significant
(and thus fastest changing) word (TT) of the current timestamp. This is followed by the next byte of the
least significant word of the current timestamp (TT). The next two bytes are the PID (PP) and the most
significant word of the current timestamp (tt) XORed.
Assuming 16bit PIDs this should result in unique IDs on a machine even with multi-threading. But there
are degenerated scenarios (more than 2**16 concurrent/fast spawning processes, while there are more than
2**8 threads bussy generating unique IDs) where the IDs might not be unique.
To avoid these use unique_machine64.
- unique_machine64()
- Generate an ID which should never repeat on this machine.
This function is suggested as the base for generating filenames and the like. Processes/Threads
running on the same machine should never be able to generate the same ID and no ID should be created
twice.
What goes where:
TTTT ^
PP ^
cccc
The first two words are the current timestamp. The next word is the current PID xored with the most
significant word of a counter. The last byte is the most significant word of a counter.
The counter is being increased by 1 in every call. This should make this function thread
save unless you call it more than 2**16 times per second.
|