Since writing lock-free code is is such a headache-inducer,
you're probably best off making some other people suffer the headaches
for you.
And those other people are the kernel folks, who have developed
quite a few lock-free building blocks so you don't have to.
For example, there's a collection of functions for manipulating interlocked ...