Never assume that a timestamp is unique

These days, I am writing a logger class. Since I want to also create a unique log transaction ID, to identify log entries belonging together from the moment the log class is initialised to the moment it is disposed, I thought I could use the time ordinal… because time always moves forward… right?


If you create the identifier for instance A, and then the NNTP client queries the NNTP Server and finds out it’s fifty seconds ahead, sets back the clock fifty seconds, your identifier is then turned back 50.000 ticks as well.

Chances that you’ll get duplicates are, of course, extremely slim, but you cannot exclude it, and if you use this identifier to determine the order in which logging sessions were initiated, that’s broken as well.

OK, back to the drawing board.

Leave a Reply

Your email address will not be published. Required fields are marked *