What are the most common configurations in which pointer entries are not atomic?

I'm interested in multithreading. There are many errors in the field, for example, there is no guarantee that pointer entries are atomic. I get this, but would like to know what are the most popular current configurations when it really is? For example, on my Macbook Pro / gcc, pointer entries definitely seem atomic.

+6
c ++ c multithreading atomic
source share
4 answers

This is mainly a problem for CPU architectures, where the pointer is wider than the width of the CPU architecture. For example, on ATmega processors, 8-bit architecture, 16-bit address space. If there are no specific instructions for loading and storing 16-bit addresses, at least two instructions are required to load / save the pointer value.

+3
source share

See here .

+2
source share

Almost every architecture influences, as Daniel said. If forced memory alignment is not performed, each record potentially leads to several operations, but this also fails if the address bus is smaller than the data bus. Therefore, you will most likely need to write code using locking mechanisms. This is a good idea anyway, as you probably want your code to be portable. For some very special architectures, these locking functions will simply be empty.

+1
source share

Pointers may not be atomic types on platforms that use segmented address space, such as MS-DOS or Win 3.x. But I do not know the modern modern desktop / server platforms that use this architecture (at least at the platform level).

However, even if the record is atomic from the point of view of the C compiler, other problems may arise that arise even in modern desktop / server systems, especially when working with multi-core / multi-processor systems (caching, memory access reordering performed at a lower level by the processor). The "atomic" APIs provided by the platform handle these problems using memory barriers (if necessary), so you should still use these APIs when trying to provide access to memory with atoms.

0
source share

All Articles