dardoria / uuid

Common Lisp implementation of UUIDs according to RFC4122
47 stars 12 forks source link

Does the system clock guarantee in-order responses? #9

Open danlentz opened 2 weeks ago

danlentz commented 2 weeks ago

Just asking out of curiosity, as when working updating clj-uuid for rfc-9562 I noticed that, even in a single thread, I could generate enough calls that I would eventually receive out-of-order clock times.

https://github.com/dardoria/uuid/blob/f0052f34a006ec995086aa3b2e42182a178fe228/uuid.lisp#L143

if so, mitigating this would require just a small additional clause:

((> last-time time-now)
  (sleep 0.0001)
  (go restart))

Similarly to here https://github.com/danlentz/clj-uuid/blob/master/src/clj_uuid/clock.clj#L68

Cheers!

danlentz commented 2 weeks ago

well, ok, the sleep 0.0001 in your loop probably helps avoid this happening in practice for single threaded. (and we're not worrying about multiple threads here). But, anyways, just passing along the experience, as it was a tricky one to figure out.