In Linux kernel context, you could plausibly prevent write stalls (other than NMIs) by masking interrupts for the write section. I guess there are some seriously slow NMIs though and we would prefer something that worked well despite those.
This doesn’t work in a VM or if there’s an SMI or if there is any other glitch.
There’s a more fundamental and harder-to-solve issue, though: time (CLOCK_MONOTONIC or whatever) is a function of the underlying clock source (TSC, for example), and that function is defined piecewise (and must be if it changes in ways that are not known in advance). And, fundamentally, if the thread evaluating the function after some change gets ahead of the thread making the change in the first place, it’s awkward to get the right answer without waiting.
The best I’ve come up with is for the thread running the show to record that, for TSC values above t, a new function is used, and to do this well in advance of t. I don’t know a way to do an atomic commit of a change if and only iff TSC < some threshold.
https://link.springer.com/content/pdf/10.1007/978-3-540-9222...
“Almost” means that you can have n copies, and the probability of waiting scales like 2^-n. Alternatively, and perhaps better, the degree of relative slowness of the reader needed to cause a wait goes like 2^n, so for any reasonable n, reads will never wait in practice. And it’s genuinely lock-free: the writer can hang at any point and read will continue to complete.
Somewhat sadly, this algorithm doesn’t seem to get much traction. I’ve considered implementing it for Linux clock reads to reduce tail latency. It’s really quite simple, and the common case works just like a seqlock.
I need to dig up the terms and conditions of this journal and post a non-paywalled version somewhere.