@ASerge
In the first case, can be, but it is almost impossible that the thread ends between two assignment operations.
That's a
trap and you just fell into it: pipe lining/branch prediction/out of order executiion.
Use an atomic operation for the assignments and you are safe.. And that is actually quite easy using the InterlockedExchange(Ptr) family.
Basically the same lack of theory that causes you to
use instead of
ignore timing.
Your reasoning is " Hey, I know it can fail, but just ignore it: it
almost never happens....." which makes your code extremely hard to debug
when it fails. Don't do it.
On modern CPU architectures it is even likely to fail because of branching: using threads like that may lead to a stall - on one of the pipe lines - in which case....???
Rest of your code is quite neat.