Given that you’re reading from the atomic variable multiple times here, there is a risk that it was updated by two threads in parallel, resulting in two different timestamps being returned from this function - which would break the independence of sends between nodes.
This is a highly unlikely event, and it may even be impossible for now (due to limited threading in the network handing code). However, with the objective of doing it “by the book”, I believe a correct implementation would be this:
0int64_t previous = next_send_inv_to_incoming.load();
1if (prevous < now) {
2 int64_t next = PoissonNextSend(now, average_interval_seconds);
3 do {
4 if (next_send_inv_to_incoming.compare_exchange_weak(previous, next)) {
5 // We succesfully updated the atomic next_send_inv_to_incoming
6 return next;
7 }
8 // Another thread changed next_send_to_inv after we fetched previous,
9 // but before we tried to update it. The values chosen by the other
10 // thread is loaded into previous, so check if that value is >= now.
11 if (previous >= now) return previous;
12 }
13}
14return previous;
(this is not a blocker for my review)