lundi 20 avril 2020

C11/C++11 atomic operations on a pointer

I have a dozen threads reading a pointer, and one thread that may change that pointer maybe once an hour or so.

The readers are super, super, super time-sensitive. I hear that atomic or whatever is the speed of going to main memory, which I want to avoid.

In modern (say, 2012 and later) server and high-end desktop Intels, can an 8-byte-aligned regular pointer be guaranteed not to tear if read and written normally? A test of mine runs an hour without seeing a tear.

Otherwise, would it be any better (or worse) if I do the write atomically and the reads normally? For instance by making a union of the two?

Note there are other questions about mixing atomic and non-atomic operations, that don't specify CPUs, and the discussion devolves into language lawyerism. This question isn't about the spec, but rather what exactly will happen, including whether we know what will happen where the spec is undefined.

Aucun commentaire:

Enregistrer un commentaire