| ▲ | amluto 3 hours ago | |||||||
If you do this, please be aware that there is absolutely no guarantee that you will not observe time going backwards. You probably will not have one thread ask for the time twice in a row and get results that are out of order, but you can have thread 1 ask for the time and do a store-release and then have thread 2 do a load-acquire, observe thread 1’s write, and ask for the time, and thread 2’s time may be earlier than thread 1’s. This is because RDTSC by itself does not respect x86’s memory order — it does not act like a load. source: I wrote a bunch of this code and I’ve tested it fairly extensively. | ||||||||
| ▲ | vlovich123 2 hours ago | parent [-] | |||||||
Do you know if the rust quanta / fastant crates have this problem? I feel like they don’t but I haven’t actually dug into the implementation. The reason I think not is that at least in the case of quanta the clock value can be made to be broadcast from a single clock maintainer thread. But even when its using plain rdtsc it says it upholds monotonicity barring kernel/virtualization bugs: https://docs.rs/quanta/latest/quanta/struct.Instant.html So I think it’s possible to do this correctly? | ||||||||
| ||||||||